HtmlAgilityPACK显示错误“给定路径的格式不受支持.从Web服务器加载html页面时 [英] HtmlAgilityPACK showing Error " The given path's format is not supported" when loading html page from web server
本文介绍了HtmlAgilityPACK显示错误“给定路径的格式不受支持.从Web服务器加载html页面时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用本地Apache服务器,其地址为127.0.0.1.我试图使用HTML Agility PACk从此服务器将html页面加载到C#程序中,但显示
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
错误:不支持给定路径的格式.
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提出建议后,我更改了COde及其工作正常
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");
推荐答案
doc.Load
采用磁盘上本地文件的路径.
doc.Load
takes a path to a local file on disk.
您应该使用HtmlWeb
类:
HtmlDocument docHtml = new HtmlWeb().Load(url);
这篇关于HtmlAgilityPACK显示错误“给定路径的格式不受支持.从Web服务器加载html页面时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文