zoukankan      html  css  js  c++  java
  • WinForm : 利用webBrowser完成填充数据并 自动登陆某网站。。。。。。。

    private void tse_Load(object sender, EventArgs e)
            {
              //this.webBrowser1.Navigate("http://www.sina.com.cn/");

              this.webBrowser1.IsWebBrowserContextMenuEnabled = true;
            }


    //此按钮登陆新浪邮箱。。。。。。。。。测试通过。
     private void button2_Click(object sender, EventArgs e)
            {
               
                HTMLDocument doc = webBrowser1.Document.DomDocument as HTMLDocument;
                //<input name="u" id="u" type="text" onfocus="shy_clear()"/>登录名
                HTMLInputElementClass input = doc.all.item("u", 0) as HTMLInputElementClass;
                input.value = "lin833";

                //<input name="psw" id="psw" type="password"/>密码
                input = doc.all.item("psw", 0) as HTMLInputElementClass;
                input.value = "33333333";

                //<input type="submit" value="登录" onclick="return log_submit();" align="absmiddle"/>登录
                //<form name="login" method="post" action="">
                webBrowser1.Document.InvokeScript("log_submit");

                HTMLFormElementClass form = doc.all.item("login", 0) as HTMLFormElementClass;
                form.submit();

            }



    //**************************************此例程用于登陆网站首页存在框架集
     private void button3_Click(object sender, EventArgs e)
            {
               
                HTMLDocument doc = webBrowser1.Document.DomDocument as HTMLDocument;
                HtmlWindow window = webBrowser1.Document.Window.Frames[0];
                doc = window.Document.DomDocument as HTMLDocument;

                HTMLInputElementClass input = doc.all.item("username", 0) as HTMLInputElementClass;
                input.value = "000";

                input = doc.all.item("passwd", 0) as HTMLInputElementClass;
                input.value = "000";

                //input = doc.all.item("rmNum", 0) as HTMLInputElementClass;
                //input.value = doc.getElementById("intImg").innerHTML.ToString();
                //input.value = "2222";

                input = doc.all.item("Submit", 0) as HTMLInputElementClass;
                input.click();

            

            }

            private void button4_Click(object sender, EventArgs e)
            {
                if (this.webBrowser1.ReadyState.ToString() == "Complete")
                {
                    //获取自动登陆后,进入规则页,再继续做点击转到默认加载页。。。
                    HTMLDocument child = webBrowser1.Document.DomDocument as HTMLDocument;
                    HtmlWindow window_2 = webBrowser1.Document.Window.Frames[0];
                    child = window_2.Document.DomDocument as HTMLDocument;

                    //HTMLInputElementClass input = child.all.item("gtype", 0) as HTMLInputElementClass;
                    //input.value = "FT";

                    HTMLInputElementClass input = child.all.item("submit", 1) as HTMLInputElementClass;
                    input.value = "我同意";
                    input.click();
                }
            }





    =====================================================

      this.Flag = "sdfa";
                ////this.Close();

                //this.DialogResult = DialogResult.OK;
                //this.Close();

                this.UserName = this.textBox1.Text.Trim();  //"1877";
                this.Password = "bb12345";
                this.rmNum = this.textBox3.Text;

                string strPostData = String.Format("uid=&langx=gb&username={0}&passwd={1}&rmNum={2}&SS={3}&SR={4}&TS={5}&&Submit=%E7%A1%AE%E8%AE%A4"
                                                        , this.UserName
                                                        , this.Password
                                                        , this.rmNum
                                                        , this.SS
                                                        , this.SR
                                                        , this.TS
                                                        );

              
                this.webBrowser1.AllowNavigation= true;
                this.webBrowser1.AllowWebBrowserDrop = true;

                //string kksdf = "uid=&langx=gb&SS=5812344&SR=3807085320&TS=4984716874&username=dpk1877&passwd=a12345&rmNum=2979&Submit=%E7%A1%AE%E8%AE%A4";

                string strHeaders = "Content-Type:  application/x-www-form-urlencoded\r\n";
                ASCIIEncoding AE = new ASCIIEncoding();
                byte[] bytePost = AE.GetBytes(strPostData);
                byte[] byteHeaders = AE.GetBytes(strHeaders);
                object vPost = bytePost;
                object vHeaders = byteHeaders; 

                string tag =null;
              
                    webBrowser1.Navigate("http://080.com/app/member/login.php", tag, bytePost, strHeaders);
               


                //webBrowser1.Navigate("http://080.com/app/member/chk_rule.php");
                this.webBrowser1.AllowNavigation = true;
               
                //axWebBrowser1.
                //object o = null;
                //object o1 = System.Text.Encoding.ASCII.GetBytes(strPostData);
                //object o2 = "Content-Type: application/x-www-form-urlencoded\r\n";  //必须要加的
                //axWebBrowser1.Navigate("http://080.com/app/member/login.php", ref o, ref o, ref o1, ref o2);


           

                //this.webBrowser1.Navigate("http://080.com/app/member/login.php", ref o, ref o1, ref o2);


                ////*************************思归...
                //object   vFlags   =   null;  
                //object   vTarget   =   null;  
                ////string   strData   =   "username=MyName&password=MyPassword";  
                //string   strHeaders   =   "Content-Type:  application/x-www-form-urlencoded\r\n";  
                //ASCIIEncoding   AE   =   new   ASCIIEncoding();
                //byte[] bytePost = AE.GetBytes(strPostData);  
                //byte[]   byteHeaders   =   AE.GetBytes(strHeaders);  
                //object   vPost   =   bytePost;  
                //object   vHeaders   =   byteHeaders;  
       
                ////   POST   the   data  
                //axWebBrowser1.Navigate("http://080.com/app/member/login.php", ref   vFlags, ref   vTarget, ref   vPost, ref    vHeaders);  

  • 相关阅读:
    块级元素和内联元素
    cookie和session 区别
    hihernate一对多关联映射
    --查询50到80行数据
    单表查询
    表空间 用户
    进程遍历模块遍历
    字符转换函数
    控件综合2
    清理文件2
  • 原文地址:https://www.cnblogs.com/Fooo/p/800295.html
Copyright © 2011-2022 走看看