Using HtmlAgilityPack to modify hyperlink tags

html-agility-pack

Question

How to use HtmlAgilityPack to Replace all hyperlinks, e.g.:

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

so that only the href attribute is left. the url.

Is this possible?

Popular Answer

Dim Doc as HtmlDocument = new HtmlDocument 
doc.LoadHtml(MyHtml)

Dim links As HtmlNodeCollection = doc.DocumentNode.SelectNodes("//a")

For Each link In links

    Dim att As HtmlAttribute = link.Attributes("href")
    MyHtml = Myhtml.Replace(link.OuterHtml, att.Value)

Next



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