[英]Python get value from input element with lxml xpath
i want to make paypal cURL login, so i need auth value. 我想要paypal cURL登录,所以我需要auth值。 i try to get auth value from html source with this python code 我尝试使用此python代码从html源获取auth值
import requests
import lxml.html
import StringIO
from xml.etree.ElementTree import ElementTree
r = requests.get("https://paypal.com/cgi-bin/webscr?cmd=_login-run")
login_page = r.text.encode('utf-8') #printing html source
html = lxml.html.fromstring(login_page) #printing <Element html at 0x7f19cb242e$
auth = html.xpath('//input[@name="auth"]') #printing [<InputElement 7fb0971e9f1$
print auth
but the above code printing this [<InputElement 7fb0971e9f18 name='auth' type='hidden'>]
, so how i can get auth value with decoded - - .
但是上面的代码打印了这个[<InputElement 7fb0971e9f18 name='auth' type='hidden'>]
,所以我如何通过解码- - .
获取auth值- - .
- - .
? ? the input section looks like this 输入部分看起来像这样
<input name="auth" type="hidden" value="ADPifNsidn-P0G6WmiMMeJbjEhnhIvZCNg7Fk11NUxc0DyYWzrH-xk5ydV.85WCzy">
thanks you very much. 非常感谢你。
If you'd like to retrieve the auth
attribute of that element, use 如果您想要检索该元素的auth
属性,请使用
auth = html.xpath('//input[@name="auth"]/@value')
there is no need to decode anything, entities are expanded automatically when lxml parses HTML, and therefore the output will be 没有必要解码任何东西,当lxml解析HTML时,实体会自动扩展,因此输出将是
$ python sample.py
['AmmyYuqCDmZRcSs6MaQi2tKhzZiyAX0eSERKqTi3pLB5pdceB726lx7jhXU2MGDN6']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.