【问题标题】:How to find hyperlinks with XPath如何使用 XPath 查找超链接
【发布时间】:2015-03-28 19:24:06
【问题描述】:

我试过了

.//*[@id='post-31']/div/div/div/a[1] 

在这个输入上:

<!-- language: lang-html -->

<div class="entry-content">
    <div class="myaccount">
        <div class="user-profile-links">
            <a href="http://store.demoqa.com/products-page/your-account/?tab=purchase_history">Purchase History</a>
            |
            <a class="current" href="http://store.demoqa.com/products-page/your-account/?tab=edit_profile">Your Details</a>
            |
            <a href="http://store.demoqa.com/products-page/your-account/?tab=downloads">Your Downloads</a>
        </div>
    </div>
</div>

【问题讨论】:

  • 这真的是整个输入文档吗(没有id为post-31的元素)?评估 XPath 表达式的上下文节点是什么(您可能希望使用 // 而不是 .//)?

标签: xpath href


【解决方案1】:

对于您发布的示例,没有具有 id 属性的根元素,这可以解释为什么它不起作用。 xpath 表达式

/div/div/div/a[1]/@href

查找第一个 a 元素的 href。

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 2011-10-12
    相关资源
    最近更新 更多