考虑以下带有重复跟随兄弟的xpath:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)
它与单个跟随兄弟的结果相同:
//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)
显然,重复的跟随兄弟会被视为重复......?那么如何达到“给我第三个成功的兄弟姐妹”的效果呢?
谢谢!
答案 0 :(得分:0)
给出以下XML:
<tr>
<td>Map</td>
<td>First</td>
<td>Second</td>
<td>Third</td>
</tr>
这些XPath(第二个来自@paul t。的建议)
//tr/td[text()='Map']/following-sibling::td[3]/text()
//tr[td='Map']/td[4]/text()
按预期返回'Third'
。