问题
so will something like this work using Hpple Xpath
//a[4]
The fourth tag in a html tree? Or do i need to do it programmatically by counting in a for() loop?
回答1:
The XPath for the fourth <a> in an HTML document is:
(//a)[4]
Your example //a[4] will produce a set of all <a>s that are the fourth <a> in their respective parent, and that is not what you want here.
See also: https://stackoverflow.com/a/14209492/1945651
来源:https://stackoverflow.com/questions/15664001/how-do-i-get-the-nth-element-with-a-certain-name-in-the-entire-xml-document