HtmlAgilityPack HtmlDocument.Load引发异常“对象未设置为实例”
作者:互联网
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);
导致错误.在Load(stream)调用上.有任何想法吗?
解决方法:
运行代码时出现的错误是:
System.ArgumentException: 'ISO-8559-1' is not a supported encoding name.
它是由标准.NET Framework编码类抛出的.这意味着页面声明了.NET不支持的编码.我这样修复:
var page = new HtmlDocument();
page.OptionReadEncoding = false;
PS:我正在使用Html Agility Pack 1.3版
标签:html-agility-pack,c 来源: https://codeday.me/bug/20191208/2092754.html