C# Convert Relative to Absolute Links in HTML String

前端 未结 10 1660
余生分开走
余生分开走 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:35

    While this may not be the most robust of solutions it should get the job done.

    var host = "http://domain.is";
    var someHtml = @"
    Relative
    
    Absolute
    
    ";
    
    
    someHtml = someHtml.Replace("src=\"" + host,"src=\"");
    someHtml = someHtml.Replace("href=\"" + host,"src=\"");
    someHtml = someHtml.Replace("src=\"","src=\"" + host);
    someHtml = someHtml.Replace("href=\"","src=\"" + host);
    

提交回复
热议问题