【问题标题】:xpath html query : select tnodes if these are not children of a given nodexpath html 查询:如果它们不是给定节点的子节点,则选择 tnodes
【发布时间】:2013-06-12 01:28:15
【问题描述】:

我是 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 个节点?

我试过了:

  1. //body[class="wrapper]/h3/*
  2. //body[class="wrapper]/h3/.

【问题讨论】:

    标签: html xml xpath xml-parsing xpathquery


    【解决方案1】:

    你要找的是following-sibling::*

    小时后的所有笔记:

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

    只有下一个

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

    接下来的三个:

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

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

    【讨论】:

    • 它完全符合我的要求,谢谢(也提供文档链接)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多