zoukankan      html  css  js  c++  java
  • 屏蔽弹出对话框

    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;
                }
            }
    
           
    
          
        }
    }
  • 相关阅读:
    angularJS---初识指令
    Bootstrap ACE后台管理界面模板-jquery已整理
    memcached和redis的区别和应用场景
    微信开发,公众号支付及微信扫描支付各自使用的密码分别来自哪里
    微信 redirect_uri参数错误 正确的处理
    jquery jsonp实现跨域
    php 常用的好函数(持续更新)
    pre 随变化的样式
    CSS 居中 可随着浏览器变大变小而居中
    2017.03.02-2017.09.28 日常随笔
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/4239981.html
Copyright © 2011-2022 走看看