屏蔽弹出对话框
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using mshtml; namespace WindowsApplication2 { public partial class Form1 : Form { //初始界面 Uri temp1 = new Uri("http://www.ahbys.com/ahbysCom/login.html"); //登陆后首页 Uri temp2 = new Uri("http://www.ahbys.com/ahbysCom/"); StreamReader sr; String line; //保存标志位 bool baocun = false; public Form1() { InitializeComponent(); sr = new StreamReader("心理学.txt"); } private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { //初次登陆时,填入信息 if (e.Url == temp1) { HtmlElement he_name = this.webBrowser1.Document.GetElementById("Name"); he_name.InnerText = "*******"; HtmlElement he_password = this.webBrowser1.Document.GetElementById("PassWord"); he_password.InnerText = "*************"; //submit 正好是4 HtmlElementCollection hec = this.webBrowser1.Document.GetElementsByTagName("input"); HtmlElement elem = hec[4]; elem.InvokeMember("click"); } //登录后进行第二次跳转 if (e.Url == temp2) { //10370 this.webBrowser1.Navigate(@"http://www.ahbys.com/ahbysCom/Dispatch/GraduateEdit_part1.aspx?a=2015&b=10370&c=10432323115292&p=Q&keyword=10432323115292&idx=1&all=1"); } //实际的工作 if (e.Url.ToString().IndexOf("http://www.ahbys.com/ahbysCom/Dispatch/GraduateEdit_part1.aspx?a=2015&b=10370") >= 0) { if (this.webBrowser1.Document.GetElementById("txtDiscipline1").GetAttribute("value") != "07000000") { this.webBrowser1.Document.GetElementById("txtDiscipline1").SetAttribute("value", "07000000"); this.webBrowser1.Document.GetElementById("txtDiscipline1").InvokeMember("onchange"); System.Threading.Thread.Sleep(100); } if (this.webBrowser1.Document.GetElementById("txtDiscipline2").GetAttribute("value") != "07150000") { this.webBrowser1.Document.GetElementById("txtDiscipline2").SetAttribute("value", "07150000"); this.webBrowser1.Document.GetElementById("txtDiscipline2").InvokeMember("onchange"); System.Threading.Thread.Sleep(100); } this.webBrowser1.Document.GetElementById("txtDiscipline").SetAttribute("value", "07150100"); } } string str = @"http://www.ahbys.com/ahbysCom/Dispatch/GraduateEdit_part1.aspx?a=2015&b=10370&c=000000000&p=Q&keyword=000000000&idx=1&all=1"; //开始遍历 private void button1_Click(object sender, EventArgs e) { this.button1.Enabled = false; this.button1.Text = "遍历"; line = sr.ReadLine(); if (line != null) { this.webBrowser1.Navigate(str.Replace("000000000", line)); baocun = true; }else MessageBox.Show("已遍历完毕!"); this.button2.Enabled = true; this.button2.Text = "保存"; } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { sr.Close(); } private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { //自动点击弹出确认或弹出提示 IHTMLDocument2 vDocument = (IHTMLDocument2)webBrowser1.Document.DomDocument; vDocument.parentWindow.execScript("function confirm(str){return ;} ", "javascript"); //弹出确认 vDocument.parentWindow.execScript("function alert(str){return;} ", "javaScript");//弹出提示 } private void button2_Click(object sender, EventArgs e) { this.button2.Enabled = false; if (baocun) { HtmlElement ImageButton3 = this.webBrowser1.Document.GetElementById("ImageButton3"); ImageButton3.InvokeMember("click"); this.button2.Text = System.DateTime.Now.ToString() + "@ 数据已保存! "; baocun = false; this.button1.Enabled = true; } } } }
版权声明:本文为qqhfeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。