See the question and my original answer on StackOverflow

Here is a good starting link here on SO: How to use HTML Agility pack

See also this: HtmlAgilityPack example for changing links doesn't work. How do I accomplish this?

And this: Finding all the A HREF Urls in an HTML document (even in malformed HTML)

To find a specific HREF, the xpath syntax would be "//a[@href='your url']", meaning: "get any A tag that has an HREF attribute equal to 'your url'.


To find an HREF if you only know the text, for example if you have the html text '<a href="homepage.html">Cars</a>' and look for homepage.html, then this is how you would do it.

        string s = @"<a href=""homepage.html"">Cars</a>";

        HtmlDocument doc = new HtmlDocument();

        HtmlNode node = doc.DocumentNode.SelectSingleNode("//a[text()='Cars']");
        Console.WriteLine("href=" + node.GetAttributeValue("href", null));