mry*_*ak3 6 html c# encoding webclient utf-8
我试图用字符串保存网站的html.该网站具有国际字符(ę,ś,ć,...),即使我将编码设置为UTF-8(对应于网站字符集),它们也不会保存到字符串中.
这是我的代码:
using (WebClient client = new WebClient())
{
client.Encoding = Encoding.UTF8;
string htmlCode = client.DownloadString(http://www.filmweb.pl/Mroczne.Widmo);
}
Run Code Online (Sandbox Code Playgroud)
当我将"htmlCode"打印到控制台时,即使在原始HTML中它们被正确显示,国际字符也不会正确显示.
任何帮助表示赞赏.
Abb*_*iri 12
我有同样的问题.似乎client.DownloadString不使用UTF-8对字符进行编码.使用client.DownloadData和编码返回的数据Encoding.UTF8.GetString解决问题.
using (WebClient client = new WebClient())
{
var htmlData = client.DownloadData("http://www.filmweb.pl/Mroczne.Widmo");
var htmlCode = Encoding.UTF8.GetString(htmlData);
}
Run Code Online (Sandbox Code Playgroud)