程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C#用firefox3.6下載yunfile的文件

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

編輯:C#入門知識

【下載說明】

1 點擊上面的地址,打開下載頁面

2 點擊"普通下載"--等待30秒--點擊"下載"按鈕--保存

 

 

備注:采用firefox3.6來下載文件,由於firefox可以自動保存某個類型的文件。且可以安裝adblock plus來阻止彈出窗口。仍然采用watin類庫。使用firefox之前需先安裝firefox的遠程控制插件,這個在下載包裡面有。


主要程序:
 
[csharp] 
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. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved