webclient不会完全下载网页

时间:2013-06-04 19:59:27

标签: c# webclient

拥有下载页面的代码:

 System.Net.WebClient client = new System.Net.WebClient();
 client.Headers.Add("user-agent", "Mozilla/20.0.1");
 byte[] feedBytes;
 string url;
 url = @"http://www.marathonbet.co.uk/en/betting/Football";
 string fullPage = string.Empty;
 try
 {
      feedBytes = client.DownloadData(url);
 }
 catch (System.Net.WebException)
 {
      return;
 }
string fullPage = Encoding.UTF8.GetString(feedBytes);

结果'fullpage'仅包含页面的一部分。在浏览器中,页面的加载逐渐发生。如何下载整页?

1 个答案:

答案 0 :(得分:0)

试试这个

public static string GetHTMLDocument(string url)
        {
            var result = "";
            using (var wc = new WebClient())
            {
                result = wc.DownloadString(url);
            }
            return result;
        }