HtmlAgilityPACK 显示错误“不支持给定路径的格式”从 Web 服务器加载 html 页面时
我正在使用本地 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,在您提出建议后我更改了我的代码并且工作正常
HtmlAgilityPack.HtmlDocument docHtml = new HtmlAgilityPack.HtmlDocument();
HtmlAgilityPack.HtmlWeb docHFile = new HtmlWeb();
docHtml = docHFile.Load("http://127.0.0.1/2.html");
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");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
doc.Load
获取磁盘上本地文件的路径。您应该使用
HtmlWeb
类:doc.Load
takes a path to a local file on disk.You should use the
HtmlWeb
class: