2010-10-17 42 views
1

我有兩個不同的錨標籤,因爲第二個不在錨文本或地址鏈接中包含單詞「Report」。如何使用XPath識別細微差別的HTML錨定標記?

<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的第一個鏈接並避免識別第二個鏈接?

+0

好問題,+1。看到我的答案,兩個簡短的解決方案:) – 2010-10-17 17:02:57

+0

嘗試此鏈接: http://stackoverflow.com/questions/915338/xpath-find-link-url-by-link-text – 2012-05-30 11:28:34

回答

1

你如何識別第一鏈接 與XPath和避免識別 第二?

有這樣做的許多方面:

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

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

這兩個XPath表達式選擇第一個a元素,不要選擇第二a元素。