我想登录网站并下载 .csv 文件,文件下载按钮位于第二个选项卡中。但是网站需要flash player。 这是我的尝试之一:
public class CookieAwareWebClient : WebClient
{
private CookieContainer cookie = new CookieContainer();
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
(request as HttpWebRequest).CookieContainer = cookie;
}
return request;
}
}
和
var client = new CookieAwareWebClient();
client.BaseAddress = @"https://example.com/";
var loginData = new NameValueCollection();
loginData.Add("username", "my user");
loginData.Add("password", "my pwd");
client.UploadValues("login/", "POST", loginData);
string htmlSource = client.DownloadString("After login page");
结果:-
EXAMPLE
Welcome to example
Example is a reporting tool that tracks your music sales. This is where you can check how your releases are selling, update your account information and see quarterly/monthly statements. Information is updated in real time, so the numbers you are seeing are current.
Why am I Seeing This Page?
If you are seeing this page, you do not have Adobe Flash Player (version 9, or higher) installed to your browser, and/or you do not have javascript enabled. If you are still seeing this page after installing Adobe Flash Player, and have javascript enabled, please contact us at support@example.com
Get Adobe's Flash Player
© example, 2007
最佳答案
您不能使用简单的 WebClient 来做到这一点。
为了满足您的需求,我建议您使用带有 Selenium 和 Chrome 驱动程序的浏览器自动化。由于浏览器已经处理 flash,您只需要使用 Selenium 来导航并执行您想要的操作。
关于c# - 如何使用 WebClient 登录到 "Flash Website"并使用 c# 下载文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370826/