上一个<a> element whose &#34;href&#34; attribute starts with a number?

时间:2016-10-29 10:37:20

标签: html xml xpath

I would like to find an XPath expression which, when applied to the page at:

https://ftp.opera.com/pub/opera-beta/

will return the text of the final <a> element whose href attribute value starts with a number.

If I had just wanted the final <a> element I could have simply written:

//body/pre/a[last()]/text()

but unfortunately the last element on this page looks like this:

<a href="info/">info/</a>

What I want is the last element whose href attribute has a value that starts with a number. This is currently this value:

<a href="41.0.2353.30/">41.0.2353.30/</a>

so what alternate XPath expression can I use to return the last value that starts with a number?

1 个答案:

答案 0 :(得分:2)

如果您使用(//a[number(substring(@href, 1, 1)) = number(substring(@href, 1, 1))])[last()],则选择文档中的最后一个a元素,其中href属性的第一个字符是数字。