日期:2014-05-17  浏览次数:20458 次

html中的相对路径变成绝对路径-高手指教
现在做一个网站页面抓取的功能,但是因为网站html的路径都是相对路径,想请教怎么解决这个问题,页面中包含a标签,img标签等,css里也有可能有img这样的相对路径的代码,外部css的引用,外部js的引用都是相对路径,请教,谢谢!

------解决方案--------------------
C# code
        string cssPath = "css/common.css";
        string htmlUrl = @"http://topic.csdn.net/u/20120925/22/953c6420-7b9d-4603-91cc-cd501a9c713f.html?id=3";
        string basePath = Path.GetDirectoryName(htmlUrl);
        string result = Path.Combine(basePath, cssPath).Replace(@"\", "/");
        Response.Write(result);