• 屏蔽弹出对话框


    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;
                }
            }
    
           
    
          
        }
    }
  • 相关阅读:
    快速幂
    三角函数与反三角函数的使用
    poj1050 dp动态规划
    归并排序算法
    KMP算法(查找子序列)
    hdu1233 继续畅通工程 (最小生成树——并查集)
    set<pair<int,int> > 的运用
    HDU 4513 吉哥系列故事――完美队形II (manacher算法)
    Codeforces Round #360 (Div. 2) C. NP-Hard Problem (BFS)
    Codeforces Round #357 (Div. 2) C.Heap Operations 优先队列 + 模拟
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/4239981.html
Copyright © 2020-2023  润新知