1
我想使用webbrowser class.i下載文件,我可以使用webbrowser進行登錄和瀏覽。自動登錄和文件下載
但該文件位於使用JavaScript的網站上。
我試圖使用網頁瀏覽器的cookies使用HttpWebRequest(fileurl)
獲取文件。
登錄後下載文件的代碼如下。
string myUri = @"url_of_file";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
request.CookieContainer = new CookieContainer();
foreach (string cookie in webBrowser1.Document.Cookie.Split(';'))
{
string name = cookie.Split('=')[0];
string value = cookie.Substring(name.Length + 1);
string path1 = "/";
string domain = ".abcde.com"; //change to your domain name
request.CookieContainer.Add(new Cookie(name.Trim(), value.Trim(), path1, domain));
}
WebResponse res = request.GetResponse();
StreamReader sReader = new StreamReader(res.GetResponseStream());
StreamWriter sWriter = new StreamWriter(@"D:\file.csv");
while (sReader.Peek() >= 0)
sWriter.WriteLine(sReader.ReadLine());
sWriter.Close();
但是,響應流沒有文件,而是在html body.as中有「url_of_file」。
<html><head></head>
<body onload="this.location.href='/Marketinfo/SubViewSubscriptionFile?product_code=DOL_INT&file_id=460916&subscription_id=318342&loadnow=true'">
</body></html>
請人所說的其實是錯在這
謝謝,我可以下載文件。因爲響應流有oonload.true.i只是加載&loadnow = true來回url.It工作。 – Radha