public string GetUrltoHtml(string Url, string type)
        {
            try
            {
                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
                System.Net.WebResponse wResp = wReq.GetResponse();
                System.IO.Stream respStream = wResp.GetResponseStream();
                using (System.IO.StreamReader reader = new System.IO.StreamReader(respStream, Encoding.GetEncoding(type)))
                {
                    return reader.ReadToEnd();
                }
            }
            catch (System.Exception ex)
            {
            }
            return "";
        }
各位大哥,我用这段代码解析网页内容
baidu什么的都能成功
但是
google首页,如http://www.google.com.hk/或http://www.google.com.tw/都解析乱码。
我想问问google首页到底是什么编码。他html明明展示的是utf-8
可是我使用utf-8 utf-16 unicode gb2312 gb18030  都不行
求教GGJJ了,谢谢大家

解决方案 »

  1.   

    大哥,试过了,没解出来,谷歌utf-8
      

  2.   

    http://blog.csdn.net/fxsjy/article/details/773184
    学习下
    都说是  谷歌utf-8
    百度gb2312
      

  3.   

    我也觉得是utf-8,但是用我那段代码走一走就解析不对,求原因
      

  4.   

     WebRequest req = WebRequest.Create("http://www.google.com.hk");
                            WebResponse result = req.GetResponse();
                            //得到的流是网页内容   
                            Stream ReceiveStream = result.GetResponseStream();
                            StreamReader readerOfStream = new StreamReader(ReceiveStream, System.Text.Encoding.GetEncoding("GB2312"));
                            //得到当前URL的源码
                            string str = readerOfStream.ReadToEnd();
    我的解析谷歌没问题!