国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

C#中將HTML匯總的相對URI更改為絕對URI

2024-08-26 00:15:36
字體:
來源:轉載
供稿:網友
  • 本文來源于網頁設計愛好者web開發社區http://www.html.org.cn收集整理,歡迎訪問。
  • 下面的代碼用以將給定的html中的所有的uri,包括href和img都更改為絕對路徑
    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;
    }

     

    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 平山县| 本溪市| 泽库县| 延吉市| 鸡西市| 喀喇沁旗| 铜山县| 天台县| 巴林右旗| 随州市| 湖口县| 上虞市| 宁化县| 大洼县| 藁城市| 寻乌县| 如皋市| 沿河| 卢氏县| 广汉市| 民勤县| 承德县| 嘉鱼县| 遂昌县| 根河市| 香港| 长春市| 湘西| 百色市| 宁阳县| 新巴尔虎左旗| 宁德市| 岐山县| 桐城市| 南溪县| 东乌| 竹北市| 万荣县| 云和县| 齐齐哈尔市| 攀枝花市|