使用 Xpath 停止分页循环



我成功地使用下面代码中显示的 xpath 来选择浏览器屏幕上显示的网页之后的网页。

如何修改 xpath,使其在页码等于 50 或 50 页后停止分页循环?

//a[@class='active_page']/following::a[1]
<div id="pagination">
   <ul class="zPagination">
      <li><a href="http://example.com/page/1">«</a></li>
      <li><a class="active_page" href="http://example.com/page/1">1</a></li>
      <li><a href="http://example.com/page/2">2</a></li>
      <li><a href="http://example.com/page/3">3</a></li>
      <li><a href="http://example.com/page/XX">XX</a></li>
      <li><a href="http://example.com/page/60">»</a></li>
   </ul>
</div>

您可以尝试使用以下 XPath 来仅匹配前 50 页的链接:

//a[@class='active_page']/following::a[position()=1 and number(text())<51]

对于 50 之后的页面:

//a[@class='active_page']/following::a[position()=1 and number(text())>50]

最新更新