C#如何把html中的相對路徑變成絕對路徑

王朝c#·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

private static string ConvertToAbsoluteUrls (string html, Uri relativeLocation) {

IHTMLDocument2 doc = new HTMLDocumentClass ();

doc.write (new object [] { html });

doc.close ();

foreach (IHTMLAnchorElement anchor in doc.links) {

IHTMLElement element = (IHTMLElement)anchor;

string href = (string)element.getAttribute ("href", 2);

if (href != null) {

Uri addr = new Uri (relativeLocation, href);

anchor.href = addr.AbsoluteUri;

}

}

foreach (IHTMLImgElement image in doc.images) {

IHTMLElement element = (IHTMLElement)image;

string src = (string)element.getAttribute ("src", 2);

if (src != null) {

Uri addr = new Uri (relativeLocation, src);

image.src = addr.AbsoluteUri;

}

}

string ret = doc.body.innerHTML;

return ret;

}

 
 
 
免責聲明:本文為網絡用戶發布,其觀點僅代表作者個人觀點,與本站無關,本站僅提供信息存儲服務。文中陳述內容未經本站證實,其真實性、完整性、及時性本站不作任何保證或承諾,請讀者僅作參考,並請自行核實相關內容。
 
 
© 2005- 王朝網路 版權所有 導航