XPath syntax to extract URL from HTMLNode using HTMLAgilityPack?

c# html-agility-pack xpath

Question

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> 

Accepted Answer

//a[@id='123']/@href

works for me.


Popular Answer

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

Using HTMLAgilityPack, the method you'd use is:

HTMLAgilityPack.HTMLNode.GetAttributeValue("href", "")



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why