In the general case of lxml, you can access the value of an element directly through the attribute .value:
>>> from lxml.html import fromstring
>>> s = """<input type="hidden" name="question" value="1234">"""
>>> doc = fromstring(s)
>>> doc.value
'1234'
In your case, you will also need to access the first element of the resulting list from the XPath query :
print fromstring(s).xpath('/html/body/div[3]/div/div[2]/div/form/input[4]')[0].value
source
share