【发布时间】:2013-01-27 19:34:32
【问题描述】:
我刚刚开始尝试使用 C# WebClient。我所拥有的是下面的代码,它从网站获取 html 代码并将其写入 .txt 文件。我唯一的问题是某些网站要求您在使用该网站之前接受 cookie。这导致不是将真实的网站 html 代码写入 .txt 文件,而是写入 cookie 弹出 html 代码。
代码:
string downloadedString;
System.Net.WebClient client;
client = new System.Net.WebClient();
//"http://nl.wikipedia.org/wiki/Lijst_van_spelers_van_het_Nederlands_voetbalelftal"
downloadedString = client.DownloadString(textBox1.Text);
using (StreamWriter write = new StreamWriter("Data.txt"))
{
write.Write(downloadedString);
}
那么解决这个问题的方法是什么?有人可以指引我走向正确的道路吗?
【问题讨论】:
-
在这种特殊情况下,API mediawiki.org/wiki/API:Main_page 可以使自动下载更容易。
-
你一定是指 .NET WebClient 类,因为没有“C# WebClient”。