【问题标题】:Why is my XPath using following-sibling not working?为什么我的使用跟随兄弟的 XPath 不起作用?
【发布时间】:2018-09-03 08:22:33
【问题描述】:

我需要选择下一个输入字段和A 字段,在下面两个示例 HTML 代码上的活动页面 (class="active_page") 之后,但是以下两个 XPath 不起作用。

我将如何完成following-sibling,最简单的方法是什么?

//*[@id="pagination"]/ul/li[2]/a/following-sibling::A[1]

<div id="pagination">
   <ul class="zPagination">
      <li><a href="https://www.test.com/page&pagination=10">«</a></li>
      <li><a class="active_page" href="https://www.test.com/page&pagination=10">1</a></li>
      <li><a href="https://www.test.com/page&pagination=10">2</a></li>
      <li><a href="https://www.test.com/page&pagination=10">3</a></li>
      <li><a href="https://www.test.com/page&pagination=10">»</a></li>
   </ul>
</div>

//TABLE[@class='table-striped']/TBODY[1]/TR[1]/TD[1]/INPUT[1]/following-sibling::INPUT[1]

<table class="table-striped">
   <tbody>
      <tr>
         <td><input id="selection" style="width: 20px;" name="test" class="zeroborder" value="001" type="radio"> </td>
         <td>S</td>
      </tr>
      <tr>
         <td><input id="selection" style="width: 20px;" name="test" class="zeroborder" value="002" type="radio"> </td>
         <td>S</td>
      </tr>
      <tr>
         <td><input id="selection" style="width: 20px;" name="test" class="zeroborder" value="003" type="radio"> </td>
         <td>S</td>
      </tr>
   </tbody>
</table>

【问题讨论】:

    标签: html xml xslt xpath web-scraping


    【解决方案1】:

    您的 XPath 有(至少)两个错误:

    1. XPath 和 XML 区分大小写。
    2. 没有following-siblings ainput 元素。可能 你的意思只是following

    【讨论】:

    • PHP 的 XPath 实现不区分大小写,而 C# 的实现区分大小写,所以我知道实现不同,但实际规范怎么说?
    • @hanshenrik:match 的 XML 定义明确声明不执行大小写折叠。
    • @hanshenrik:您是否有参考或其他证据证明 XPath 中的 XML 匹配在 PHP 中不区分大小写?
    • @kjhughes:以上两个 xpath 现在都在使用 following 而不是 following-sibling。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多