Gzip,HTMLAgilitypack

时间:2018-12-10 07:45:31

标签: c# parsing gzip html-agility-pack

我在HTMLAgillityPack中使用Gzip遇到了一些问题 错误-'gzip'不是受支持的编码名称

代码:

var url = "http://poe.trade/search/arokazugetohar";
var web = new HtmlWeb();

var htmldoc = web.Load(url);

1 个答案:

答案 0 :(得分:0)

您可以使用以下方法添加gzip编码。

var url = "http://poe.trade/search/arokazugetohar";

HtmlWeb webClient = new HtmlWeb();
HtmlAgilityPack.HtmlWeb.PreRequestHandler handler = delegate (HttpWebRequest request)
{
    request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
    request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
    request.CookieContainer = new System.Net.CookieContainer();
    return true;
 };
 webClient.PreRequest += handler;

 HtmlDocument doc = webClient.Load(url);