从Web服务器加载html页面时,HtmlAgilityPACK显示错误“不支持给定路径的格式”

我正在使用我的本地Apache服务器,其地址是127.0.0.1。 我尝试使用HTML Agility PACk从该服务器加载html页面到C#程序,但它的显示

错误:不支持给定路径的格式。

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"); } 

非常感谢@Slaks在你提出建议之后我改变了我的COED并且工作正常

  HtmlAgilityPack.HtmlDocument docHtml = new HtmlAgilityPack.HtmlDocument(); HtmlAgilityPack.HtmlWeb docHFile = new HtmlWeb(); docHtml = docHFile.Load("http://127.0.0.1/2.html"); 

doc.Load获取磁盘上本地文件的路径。

你应该使用HtmlWeb类:

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