首页 文章

xpath html query:如果这些不是给定节点的子节点,则选择tnodes

提问于
浏览
0

我是xpath的新手,今天开始看它吧:)

我有一些html具有以下结构:

<body class="wrapper">
   <h3>someText_1</h3>
   <h4>someOtherText_1
      <a href="someLink_1"> link_1 </a>
   </h4>
   <p>description_1</p>
          ...     
   <h3>someText_n</h3>
   <h4>someOtherText_n
      <a href="someLink_n"> link_1 </a>
   </h4>
   <p>description_1</p>
</body>

是否可以使用xpath选择每个h3后的所有节点?或者更一般地说:给定节点是否可以选择以下n节点,如果它们不是给定节点的子节点?

我尝试过:

  • // body [class =“wrapper] / h3 / *

  • // body [class =“wrapper] / h3 / .

1 回答

  • 0

    你在找什么是 following-sibling::*

    hr之后的所有笔记:

    //body[@class="wrapper"]/h3/following-sibling::*
    

    只有下一个

    //body[@class="wrapper"]/h3/following-sibling::*[1]
    

    接下来的三个:

    //body[@class="wrapper"]/h3/following-sibling::*)[position() <= 3 ]'
    

    欲了解更多信息,请查看xpah axes

相关问题