This project has moved. For the latest updates, please go here.

Extract href by anchor text?

Oct 6, 2010 at 7:20 AM


I'm brand new to agilitypack and did some searching but did not find what I was looking for. I want to be able to extract the href part of a html link, by the "Link text".

<a href="">Link text</a>


Can this be done? if so how?


Best Regards!

Jun 9, 2014 at 3:57 AM
I see that this was never answer, but just in case someone else is looking for answer, here is one way of doing it:

var htmlDoc = new HtmlDocument();
var rootNode = htmlDoc.DocumentNode;
var refs = rootNode.SelectNodes("//*/a/@href");
var link =refs.ElementAt(0).Attributes["href"].Value;