HtmlAgilityPack - How to set custom encoding when loading pages

前端 未结 3 346
春和景丽
春和景丽 2021-01-17 04:44

Is it possible to set custom encoding when loading pages with the method below?

HtmlWeb hwWeb = new HtmlWeb();
HtmlDocument hd = hwWeb.load(\"myurl\");
         


        
3条回答
  •  不知归路
    2021-01-17 05:26

    I suppose you could try overriding the encoding in the HtmlWeb object.

    Try this:

    var web = new HtmlWeb
    {
        AutoDetectEncoding = false,
        OverrideEncoding = myEncoding,
    };
    var doc = web.Load(myUrl);
    

    Note: It appears that the OverrideEncoding property was added to HTML agility pack in revision 76610 so it is not available in the current release v1.4 (66017). The next best thing to do would be to read the page manually with the encodings overridden.

提交回复
热议问题