views:

16

answers:

2

What is the proper XPath syntax to grab the value of the href attribute from the following HTMLNode:

<a target="_blank" class="monkeys" href="http://someurl.com" id="123">
    <span class="title">Monkeys are flying all over!</span>
</a> 
+3  A: 
//a[@id='123']/@href

works for me.

adamse
A: 

Is //a@href what you're looking for?

Using HTMLAgilityPack, the method you'd use is:

HTMLAgilityPack.HTMLNode.GetAttributeValue("href", "")
LesterDove
That is invalid, you probably want `//a/@href`, which will find the `href` attribute of any number of `a` elements. I believe (as reflected in my answer) that "Darth" is looking for that specific `a` element.
adamse