Extract href by anchor text?

Oct 6, 2010 at 8:20 AM

Hello

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="http://link.com">Link text</a>

 

Can this be done? if so how?

 

Best Regards!

Jun 9, 2014 at 4: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();
htmlDoc.LoadHtml({yourHtmlContentOrFile});
var rootNode = htmlDoc.DocumentNode;
var refs = rootNode.SelectNodes("//*/a/@href");
var link =refs.ElementAt(0).Attributes["href"].Value;