C# Convert Relative to Absolute Links in HTML String

前端 未结 10 1661
余生分开走
余生分开走 2020-12-16 04:03

I\'m mirroring some internal websites for backup purposes. As of right now I basically use this c# code:

System.Net.WebClient client = new System.Net.WebCli         


        
10条回答
  •  无人及你
    2020-12-16 04:49

    You could use the HTMLAgilityPack accomplish this. You would do something along these (not tested) lines:

    • Load the url
    • Select all links
    • Load the link into a Uri and test whether it is relative If it relative convert it to absolute
    • Update the links value with the new uri
    • save the file

    Here are a few examples:

    Relative to absolute paths in HTML (asp.net)

    http://htmlagilitypack.codeplex.com/wikipage?title=Examples&referringTitle=Home

    http://blog.abodit.com/2010/03/a-simple-web-crawler-in-c-using-htmlagilitypack/

提交回复
热议问题