Csharp/C#教程:从Web服务器加载html页面时,HtmlAgilityPACK显示错误“不支持给定路径的格式”分享


从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("https://127.0.0.1/2.html"); 

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

你应该使用HtmlWeb类:

上述就是C#学习教程:从Web服务器加载html页面时,HtmlAgilityPACK显示错误“不支持给定路径的格式”分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1002028.html

(0)
上一篇 2021年12月27日
下一篇 2021年12月27日

精彩推荐