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/