Html Agility Pack Load method issue

asp.net c# html-agility-pack

Question

I am using the Html Agility pack. When the Load method of HtmlDocument class is passed the URL like "http://www.stackoverflow.com" it says the URI is not in correct format.

    doc.Load(TextBoxUrl.Text, Encoding.UTF8 );

the url I try is this http://www.stackoverflow.com/questions/846994/how-to-use-html-agility-pack

1
0
8/24/2012 6:31:42 PM

Accepted Answer

HAP can not load from url, only from file or from a string. Use WebClient or HttpWebRequest to get the page.

For example:

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
using (var wc = new WebClient())
{
    doc.LoadHtml(wc.DownloadString(TextBoxUrl.Text));
}
1
8/24/2012 6:57:10 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow