HtmlAgilityPACK showing Error “ The given path's format is not supported” when loading html page from web server

[亡魂溺海] 提交于 2019-12-01 02:51:04

问题


I am using my local Apache Server and its address is 127.0.0.1 . and i trying to load html page from this server to C# programme using HTML Agility PACk but its showing

ERROR : The given path's format is not supported.

  HtmlAgilityPack.HtmlDocument docHtml = new HtmlAgilityPack.HtmlDocument();

        docHtml.Load(@"htttp://127.0.0.1/2.htm"); // <---  error pointer showing here 

        foreach(HtmlNode link in docHtml.DocumentNode.SelectNodes("//a[@href]"))

        {  link.Attributes.Append("class","personal_info");


        }
        docHtml.Save("testHTML.html");


    }

Thank You very Much @Slaks after your suggesion i Changed my COde and its working Fine

 HtmlAgilityPack.HtmlDocument docHtml = new HtmlAgilityPack.HtmlDocument();
        HtmlAgilityPack.HtmlWeb docHFile = new HtmlWeb();

        docHtml = docHFile.Load("http://127.0.0.1/2.html");

回答1:


doc.Load takes a path to a local file on disk.

You should use the HtmlWeb class:

HtmlDocument docHtml = new HtmlWeb().Load(url);


来源:https://stackoverflow.com/questions/6542949/htmlagilitypack-showing-error-the-given-paths-format-is-not-supported-when-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!