htmlagilitypack gzip encryption exception

前端 未结 1 625
伪装坚强ぢ
伪装坚强ぢ 2021-01-06 03:38

I\'m having the exception throw gzip is not support. This is all i\'m using the load the page, any idea on how to allow gzip?

        HtmlWeb hwObject = new         


        
相关标签:
1条回答
  • 2021-01-06 04:20

    You can download the page yourself, i.e. using a class derived from WebClient (or manually making a WebRequest and setting AutomaticDecompression )

    public class GZipWebClient : WebClient
    {
        protected override WebRequest GetWebRequest(Uri address)
        {
            HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address);
            request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
            return request;
        }
    }
    

    Given this you can do:

    string html;
    using(var wc = new GZipWebClient())
      html = wc.DownloadString(siteUrl);
    
    var htmldocObject = new HtmlDocument();
    htmldocObject.LoadHtml(html);
    
    0 讨论(0)
提交回复
热议问题