I have a well formed XHTML page. I want to find the destination URL of a link when I have the text that is linked.
Example
<a href="http://stackoverflow.com">programming questions site</a>
<a href="http://cnn.com">news</a>
I want an XPath expression such that if given programming questions site
it will give http://stackoverflow.com
and if I give it news
it will give http://cnn.com
.
Think of the phrase in the square brackets as a WHERE clause in SQL.
So this query says, "select the "href" attribute (@) of an "a" tag that appears anywhere (//), but only where (the bracketed phrase) the textual contents of the "a" tag is equal to 'programming questions site'".
Should be something similar to:
Too late for you, but for anyone else with the same question...
Of course, 'programming' can be any text fragment.
if you are using html agility pack use getattributeValue:
For case insensitive contains, use the following:
translate converts capital letters in PROGRAMMING to lower case programming.
which basically identifies an anchor node
<a>
that has the text you want, and extracts thehref
attribute.