XPath 谓语:方括号 [ ]

 

谓语被嵌在方括号中

复杂的谓语结合其他XPath函数使用

桔色字体表示使用语法匹配的结果

语法://span[1]  匹配第一个span节点
<span id="s1"></span>
<span id="s2"></span>
<span></span>
语法://span[last()]  匹配最后一个span节点
<span id="s1"></span>
<span id="s2"></span>
<span></span>
语法://span[last()-1]  匹配倒数第二个span节点
<span id="s1"></span>
<span id="s2"></span>
<span></span>
语法://span[position()<3]  匹配前两个span节点
<span id="s1"></span>
<span id="s2"></span>
<span></span>
语法://span[title>5]  匹配span标签的子节点title大于5的节点
<span id="s1">
    <title>20</title>
</span>
<span id="s2"></span>
<span></span>
语法://span[title>5]/p 
<span id="s1">
    <title>20</title>
    <p></p>
</span>
<span id="s2"></span>
<span></span>

 

posted @ 2017-10-27 16:41  coco1989  阅读(2346)  评论(0编辑  收藏  举报