HtmlAgilityPack HtmlDocument.Load throws an exception "object not installed in the instance"

var uri = new Uri("http://store.scrapbook.com/cos-pad825.html?t12-13=cosmo%20cricket&date=20110309");
var request = (HttpWebRequest)WebRequest.Create(url);
var cookieContainer = new CookieContainer();

request.CookieContainer = cookieContainer;
request.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5";
request.Method = "GET";
request.AllowAutoRedirect = true;
request.Timeout = 15000;

var response = (HttpWebResponse)request.GetResponse();
var page = new HtmlDocument();
var stream = response.GetResponseStream();
page.Load(stream);

Causes an error. on call to Load (stream). Any ideas?

+3
source share
2 answers

The error I get when running your code:

System.ArgumentException: 'ISO-8559-1' is not a supported encoding name.

It is generated by the standard .NET Framework encoding classes. This means that the page declares an encoding that is not supported by .NET. I fixed it as follows:

var page = new HtmlDocument();
page.OptionReadEncoding = false;

PS: I am using the Html Agility Pack version 1.3

+3
source

, , , , , .
, TextReader htmldocument . var htmldoc.

htmlagility, , , /, .

0

All Articles