【下載說明】
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);
}
}
}