我正在使用本地 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");
doc.Load
获取磁盘上本地文件的路径。
您应该使用HtmlWeb
class:
HtmlDocument docHtml = new HtmlWeb().Load(url);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)