我环顾四周,似乎无法找到答案。
非常简化:
<a>
<b>
<div class=label>
<label="here"/>
</div>
</b>
<div id="something">
<b>
<div class=label>
<label="here"/>
</div>
</div>
</a>
所以我试图捕获第二个“这里”标签。我想做的是做 id 到“某事”部分
//.[@id="something”]
然后从那时起搜索标签,例如
//.[@class="label" and label="here"]
但是从阅读其他一些回复来看,似乎并不像
//.[@id="something”][@class="label" and label="here"]
有效,我只是想知道我是否只是遗漏了它的工作原理?我知道我可以用另一种方法简单地得到上述内容,这只是一个示例,询问如何在两个谓词之后执行两个谓词语句(如果确实可能的话)。
谢谢!
最佳答案
我认为你需要这样的东西:
//.[@id="something”]//.[@class="label" and label="here"]
关键是//表示:从当前节点中选择文档中与选择匹配的节点,无论它们在哪里
引用:http://www.w3schools.com/xpath/xpath_syntax.asp
关于具有多个谓词语句的 Xpath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25670320/