gpt4 book ai didi

C# HtmlAgilityPack HtmlDocument() LoadHtml编码

转载 作者:太空狗 更新时间:2023-10-29 22:51:54 25 4
gpt4 key购买 nike

Uri url = new Uri("http://localhost/rgm.php");
WebClient client = new WebClient();
string html = client.DownloadString(url);

HtmlAgilityPack.HtmlDocument doc23 = new HtmlAgilityPack.HtmlDocument();
doc23.LoadHtml(html);

HtmlNode body23 = doc23.DocumentNode.SelectSingleNode("//body");

string content23 = body23.InnerHtml;

我如何强制它使用“UTF-8”编码解析网页?

最佳答案

使用 WebClient 的 DownloadData 方法代替 DownloadString():

WebClient client = new WebClient();
var data = client.DownloadData(url);
var html = Encoding.UTF8.GetString(data);

关于C# HtmlAgilityPack HtmlDocument() LoadHtml编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18269983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com