WebClient MyWebClient = new WebClient();
                MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据
                Byte[] pageData = MyWebClient.DownloadData("http://rate.taobao.com/user-rate-d0b16a349ceaa2c738aff0a5deccbdd0.htm"); //从指定网站下载数据
                Console.WriteLine(Encoding.Default.GetString(pageData));//在控制台输入获取的内容
                Console.ReadLine(); 
为什么只要网页源码少,就能获取完整的源码,而源码多时,只能获取部分源码,各位大神,这个怎么解决??webClient 获取网页源码webClient获取网页源码

解决方案 »

  1.   


    //测试没什么问题
    string str =  System.Text.Encoding.Default.GetString(new System.Net.WebClient().DownloadData("http://rate.taobao.com/user-rate-d0b16a349ceaa2c738aff0a5deccbdd0.htm"));
      

  2.   

    你可以直接使用WebClient.DownloadString 方法来下载资源的,没不要做一步转化。 public static void DownloadString (string address)
        {
            WebClient client = new WebClient ();
            string reply = client.DownloadString (address);        Console.WriteLine (reply);
        }
      

  3.   

    我估计那是因为你用了Console模式显示。平时用命令行都有这样的“效果”,没有留意?
    把内容输出到一个文字文件就ok了。