I'm getting html source from this url : "http://duhoc.dantri.com.vn/du-hoc/30-hoc-sinh-trung-tuyen-dai-hoc-my-nam-2018-chia-se-bi-kip-thanh-cong-20180418093640358.htm" by :
private static string getPageSource(string url)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "SO/1.0";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
//if (response.CharacterSet == null)
//{
readStream = new StreamReader(receiveStream, Encoding.UTF8);
//}
string data = readStream.ReadToEnd();
response.Close();
readStream.Close();
return data;
}
}
catch (Exception ex)
{
WriteLog("Exception get Page Source, Ex = " + ex.ToString());
}
return null;
}
The title of the page on browser display like this: "30 học sinh trúng tuyển đại học Mỹ năm 2018 chia sẻ “bí kíp” thành công" but when I get html source from that page by calling method given above the title of the page became "30 học sinh trúng tuyển đại học Mỹ năm 2018 chia sẻ “bí ; kí ; p” thà ; nh cô ; ng". To resolve this I've change UTF8 tobe:
Encoding encode = System.Text.Encoding.GetEncoding(1255)
and UTF7,UTF32 but nothing is working.So, what am I doing wrong?
30 học sinh trúng tuyển đại học Mỹ năm 2018 chia sẻ “bí kíp” thành công
`. The HTML actually contains these values. – ProgrammingLlama Apr 18 '18 at 04:53