【发布时间】:2013-05-31 08:34:37
【问题描述】:
有下载页面的代码:
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' 仅包含页面的一部分。在浏览器中页面的加载是逐渐发生的。如何下载整页?
【问题讨论】:
-
为什么忽略异常?删除那个 try/catch 块,看看会发生什么。至少,捕获异常并显示
ex.ToString(),这样您就知道出了什么问题。 -
您的代码对我有用。执行您的代码后,我在
fullPage中获得了整页... -
nemsv - 我想你收到了大约 300 Kb 的信息,整页超过 2 Mb
-
添加以捕获 'Console.WriteLine("WebException");'。结果没有改变。
-
问题很可能是页面使用JavaScript生成内容,而
WebClient.DownloadData不执行JavaScript;它只是下载那一页。