0

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> 

2 Answers 2

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

works for me.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Using HTMLAgilityPack, the method you'd use is:

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

2 Comments

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.
i am using HtmlAgilityPack.HtmlNode.GetAttributeValue() but it does not seem to work for attributes that are defined using single quotes like this: <a href='adomain.com/page'>link</a>. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.