I haven’t used XPath much, so bear with me. I have an HTML file that contains two forms, each of which contains some input/select elements.
In [146]: len(doc.xpath('//input | //select'))
Out[146]: 14
In [147]: len(doc.xpath('//form'))
Out[147]: 2
Is there a way to loop through forms and find respective input / select elements? At the moment it returns all the elements twice.
In [149]: for e in doc.xpath('//form'):
...: print len(e.xpath('//input | //select'))
...:
14
14
I dont know XPath integration in python, but I think you can try :
in your for loop.
eis a node attached to the whole document. When you perform XPath on it, you should stay in this context. When you use//, you are in the document context.