Python get value from input element with lxml xpath

I want to make a paypal cURL login so I need the auth value. i am trying to get auth value from html source using this python code

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 prints this [<InputElement 7fb0971e9f18 name='auth' type='hidden'>]

, so how can I get the auth value with the decoded &#x2d; &#x2d; &#x2e;

? the input section looks like this:

<input name="auth" type="hidden" value="ADPifNsidn&#x2d;P0G6WmiMMeJbjEhnhIvZCNg7Fk11NUxc0DyYWzrH&#x2d;xk5ydV&#x2e;85WCzy">

      

Many thanks.

+3


source to share


1 answer


If you want to get the attribute of auth

this element use

auth = html.xpath('//input[@name="auth"]/@value')

      



there is no need to decrypt anything, entities are automatically expanded when lxml parses HTML and so the output will be

$ python sample.py 
['AmmyYuqCDmZRcSs6MaQi2tKhzZiyAX0eSERKqTi3pLB5pdceB726lx7jhXU2MGDN6']

      

+3


source







All Articles