Webclient.DownloadString 不检索整个页面 [英] Webclient.DownloadString does not retrieve the whole page
问题描述
我正在尝试使用 WebClient.DownloadString 检索
浏览器调试:
代码:
公共字符串 GetWebpageSource(){使用 (WebClient 客户端 = new WebClient()){client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0(Windows NT 10.0; Win64; x64; rv: 44.0) Gecko/20100101 Firefox/44.0";client.Encoding = Encoding.UTF8;string htmlcode = client.DownloadString("http://2007.runescape.wikia.com/wiki/Bandos%20page%201");返回html代码;}}
所以我想知道为什么会这样?如果需要其他信息,我会发布.感谢阅读!
感谢来自 SO 的人们,我找到了问题".VS 中的文本可视化器告诉我文本被截断了,但这不是将源文件写入文件时的问题.所以我认为它没有下载整个页面,因为文本可视化器中的文本.所以我学到的教训是不要相信文本可视化工具!
通过进一步调试文本文件,我可以解决我的问题:)
I'm trying to retrieve the source of a site with WebClient.DownloadString, but when i debug the string I'm writing the source to it seems to cut off a part of the html source.
Text visualiser in VS:
Browser debug:
Code:
public string GetWebpageSource()
{
using (WebClient client = new WebClient())
{
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla / 5.0(Windows NT 10.0; Win64; x64; rv: 44.0) Gecko / 20100101 Firefox / 44.0";
client.Encoding = Encoding.UTF8;
string htmlcode = client.DownloadString("http://2007.runescape.wikia.com/wiki/Bandos%20page%201");
return htmlcode;
}
}
So I'm wondering why it does that? If there's additional info needed, I will post it. Thanks for reading!
Thanks to people from SO I've found the 'problem'. The text visualiser in VS gave me an indication that the text was cut off, but this was not the problem when writing the source to a file. So I thought it did not download the whole page because the text in the text visualiser. So the lession I've learned is do NOT trust the text visualiser!
By further debugging from the text file I could solve my problems :)
这篇关于Webclient.DownloadString 不检索整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!