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

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

【下载说明】

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

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


C#用firefox3.6下载yunfile的文件_第1张图片


备注:采用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.GetProcessesByName("firefox");
					p[0].Kill();
				}catch(Exception ex){
					MessageBox.Show(ex.Message,"Exception");
				}
				textBox2.Text += n.ToString() + "-->" + "Wait 600 seconds to download next time...";
				temp = textBox2.Text;
				for(int i=0;i<600;i++){
					string t = temp;
					textBox2.Text = t + (i+1).ToString() + " seconds";
					Thread.Sleep(1000);
				}
			}
		}



【更多阅读】
  1. [译]TIOBE 2012年10月份编程语言排行榜
  2. [译]使用WM_COPYDATA消息在C++和C#程序之间互传数据
  3. [译]C#水波纹效果控件的实现
  4. [译]用C#检测你的打印机是否连接
  5. [原]PjWebApps:将常用网址最顶端显示并一键打开
  6. [译]使用OpenXML更新Word文档中的表格
  7. [译]C#实现同一个对话框打开目录和文件
  8. [原]C#将文本转换为图片,支持中文字符
  9. [原]IT6633P V0.19 数据手册、设计电路图、程序源代码
  10. [译]C#检测程序是否已经运行并置顶

你可能感兴趣的:(exception,C#,firefox,download,button,textbox)