HtmlAgilityPack - How to set custom encoding when loading pages

前端 未结 3 342
春和景丽
春和景丽 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:31

    var document = new HtmlDocument();
    
    using (var client = new WebClient())
    {
        using (var stream = client.OpenRead(url))
        {
            var reader = new StreamReader(stream, Encoding.GetEncoding("iso-8859-9"));
            var html = reader.ReadToEnd();
            document.LoadHtml(html);
        }
    }
    

    This is a simple version of the solution answered here (for some reasons it got deleted)

提交回复
热议问题