1

I'm trying to use C# to download the source of this website http://www.dotnetperls.com/net and do some parsing. I'm using this function:

WebClient client = new WebClient();
string website = client.DownloadString("http://www.dotnetperls.com/net");

The code I'm getting is unreadable though, here's an excerpt of it:

‹     „VoŰ8ý*Ü5Řţ!;q6UlárŰt ×öę ÷7%Ž,n(R%)˙XĂßý†¤ĺH¶€  IĎ{3śyCRYüÂTf÷–"YśF ,Y»0ľÔpŔ%Ők.ăÜLŁjG¦3>V»‡\(jcÍ×…}HiöşÖŞ–lT)Ă-W2¶Ş"W¨†
ĐKŞÓę8‡-g¶góŕ<âéGüq”
vŰÂf‘ÇXÝ´°Ű;ŹU

I checked the website source in firefox and it seems just fine. What am I doing wrong?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Marcin
  • 380
  • 3
  • 20

1 Answers1

2

You should use web client encoding before calling DownloadString:

using(WebClient webClient = new WebClient())
{
   webClient.Encoding = Encoding.UTF8;
   string s = webClient.DownloadString("http://www.dotnetperls.com/net");
}
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110