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

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));
}



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why