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

我试过了:

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

1 回答 1

0

你正在寻找的是following-sibling::*

小时后的所有注释:

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

只有下一个

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

接下来三个:

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

有关更多信息,请查看xpah 轴

于 2013-06-15T14:53:14.340 回答