【问题标题】:How to identify subtly different HTML anchor tags with XPath?如何使用 XPath 识别细微不同的 HTML 锚标记?
【发布时间】:2010-10-17 16:45:44
【问题描述】:

我有两个锚标记不同,只是因为第二个在锚文本或地址链接中不包含单词“Report”。

<a href="http://www.example.com/data/invoices/2010/10/invoices-report---tuesday-october-12.html">Invoices Report - Tuesday, October 12</a>

<a href="http://www.example.com/data/invoices/2010/10/invoices---tuesday-october-12.html">Invoices - Tuesday, October 12</a>

您将如何使用 XPath 识别第一个链接并避免识别第二个?

【问题讨论】:

标签: xpath


【解决方案1】:

您如何识别第一个链接 使用 XPath 并避免识别 第二个?

有很多方法可以做到这一点:

//a[contains(., 'Report')]

//a[contains(@href,'report')]

这两个 XPath 表达式都选择第一个 a 元素,而不选择第二个 a 元素。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2013-12-29
    • 2012-04-11
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    相关资源
    最近更新 更多