使用HtmlAgilityPack修改超链接标记

时间:2009-06-12 10:03:48

标签: html-agility-pack

如何使用HtmlAgilityPack替换所有超链接,例如:

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

这样只剩下href属性。网址。

这可能吗?

1 个答案:

答案 0 :(得分:5)

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