日期:2014-05-17  浏览次数:20908 次

C#用firefox3.6下载yunfile的文件

下载地址: 【北方网通】    【电信网通】

【下载说明】

1 点击上面的地址,打开下载页面

2 点击"普通下载"--等待30秒--点击"下载"按钮--保存



备注:采用firefox3.6来下载文件,由于firefox可以自动保存某个类型的文件。且可以安装adblock plus来阻止弹出窗口。仍然采用watin类库。使用firefox之前需先安装firefox的远程控制插件,这个在下载包里面有。


主要程序:

void OperThread(){
			while( !isExitOperThread ){
				n++;
				string url = textBox1.Text;
				textBox2.Text += "\r\n" + n.ToString() + "-->" +"Navigate firefox to target address...\r\n";
				firefox = new FireFox();
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				firefox.GoTo(url);
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				textBox2.Text += n.ToString() + "-->" + "Wait firefox to complete...\r\n";
				firefox.WaitForComplete();
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				textBox2.Text += n.ToString() + "-->" + "Find the slow button and click...\r\n";
				firefox.Button(Find.ById("slow_button")).Click();
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				textBox2.Text += n.ToString() + "-->" + "Wait firefox to complete...\r\n";
				firefox.WaitForComplete();
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				textBox2.Text += n.ToString() + "-->" + "Wait 45 seconds to download...";
				string temp = textBox2.Text;
				for(int i=0;i<45;i++){
					string t = temp;
					textBox2.Text = t + (i+1).ToString() + " seconds";
					Thread.Sleep(1000);
				}
				
				textBox2.Text += "\r\n" + n.ToString() + "-->" + "Find the download button and click...\r\n";
				try{
					firefox.Button(Find.ByValue("下载")).Click();
				}catch(Exception){
					firefox.Button(Find.ByValue("Download")).Click();
				}
				firefox.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ForceMinimized
				                  | WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.ShowNoActivate);
				
				textBox2.Text += n.ToString() + "-->" + "Wait 10 seconds to download file...";
				temp = textBox2.Text;
				for(int i=0;i<10;i++){
					string t = temp;
					textBox2.Text = t + (i+1).ToString() + " seconds";
					Thread.Sleep(1000);
				}
				textBox2.Text += "\r\n" + n.ToString() + "-->" + "Close all the opened window...\r\n";
				
				firefox.Close();
				firefox.Dispose();
				firefox = null;
				
				try{
					Process[] p = Process.GetP