How do I get the nth element with a certain name in the entire XML document?

允我心安 提交于 2019-12-11 18:39:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!