当前位置:编程学习 > C#/ASP.NET >>

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

【下载说明】

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() + "-->" + &qu

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,