Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ///
            /// 获取webbrowser里的图片
            ///
            HTMLDocument html = (HTMLDocument)webBrowser1.Document.DomDocument;//注意是HTMLDocument而不是HtmlDocument
            //寻找验证码图片,因为没有ID所以得自己定位
            HtmlElement         elem  = webBrowser1.Document.GetElementById("icode");
            IHTMLControlElement img   = (IHTMLControlElement)elem.DomElement;
            IHTMLControlRange   range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();

            range.add(img);
            range.execCommand("Copy", false, null);

            if (Clipboard.ContainsImage())
            {
                Image pic = Clipboard.GetImage();
                this.pictureBox1.Image = pic;

                Bitmap bitmap = (Bitmap)pic.Clone();

                bitmap.Save(Application.StartupPath + "\\numbers\\" + DateTime.Now.Ticks.ToString() + ".bmp");

                JWDecode decode = new JWDecode();
                string   result = decode.Decode(bitmap, Application.StartupPath + "\\numbers2\\");
                label1.Text = result;
            }
        }
Exemplo n.º 2
0
        private Image GetCheckImage(HtmlElement ImageTag)
        {
            HTMLDocument doc = (HTMLDocument)webBrowser1.Document.DomDocument;

            HTMLBody body = (HTMLBody)doc.body;

            IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();

            IHTMLControlElement Img = (IHTMLControlElement)ImageTag.DomElement; //圖片地址

            bool containImg  = Clipboard.ContainsImage();
            bool containText = Clipboard.ContainsText();

            Image  oldImage = Clipboard.GetImage();
            string oldText  = Clipboard.GetText();

            rang.add(Img);

            rang.execCommand("Copy", false, null); //拷貝到內存

            Image numImage = Clipboard.GetImage(); //從Clipboard中取圖

            if (containImg)
            {
                try { Clipboard.SetImage(oldImage); } //還原
                catch { }
            }
            else if (containText)
            {
                try { Clipboard.SetText(oldText); } //還原
                catch { }
            }

            return(numImage);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        public static Image GetWebImage(Form1 form, WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            Image image = null;

            form.Invoke((EventHandler)(delegate
            {
                // 这里写你的控件代码,比如
                HTMLDocument doc = (HTMLDocument)WebCtl.Document.DomDocument;
                HTMLBody body = (HTMLBody)doc.body;
                IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement Img = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

                Image oldImage = Clipboard.GetImage();
                rang.add(Img);
                rang.execCommand("Copy", false, null);  //拷贝到内存
                image = Clipboard.GetImage();
                try
                {
                    Clipboard.SetImage(oldImage);
                }
                catch
                {
                }
            }
                                       ));

            return(image);
        }
Exemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            var id = ConfigurationManager.AppSettings["ImgId"];

            var img = webBrowser1.Document.GetElementById(id);

            img.InvokeMember("click");

            HTMLDocument        html  = (HTMLDocument)this.webBrowser1.Document.DomDocument;
            IHTMLControlElement img2  = (IHTMLControlElement)webBrowser1.Document.Images[id].DomElement;
            IHTMLControlRange   range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();

            range.add(img2);
            range.execCommand("Copy", false, null);

            if (Clipboard.ContainsImage())
            {
                pictureBox1.Image = Clipboard.GetImage();
            }
            else
            {
                MessageBox.Show("获取验证码失败");
            }

            Clipboard.Clear();

            pictureBox2.Image = VerificationCode.ProcessBmp(new Bitmap(pictureBox1.Image));
            textBox1.Text     = VerificationCode.Spot(new Bitmap(pictureBox1.Image), 4);
        }
Exemplo n.º 5
0
        private Image GetWebImage(HTMLDocument doc, IHTMLControlElement ImgeTag)
        {
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = ImgeTag; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            try
            {
                if (oldImage != null)
                {
                    Clipboard.SetImage(oldImage);
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show("GetWebImage:" + ex.Message);
            }

            return(numImage);
        }
Exemplo n.º 6
0
 private void timer_0_Tick_5(object sender, EventArgs e)
 {
     try
     {
         this.SetVerifyVisible(true);
         this.timer_0.Stop();
         if (!this.bool_0)
         {
             this.method_7();
         }
         this.method_9("正在【打码】!");
         this.ihtmldocument2_0 = (IHTMLDocument2)this.webBrowserLoginAlimama.Document.DomDocument;
         IHTMLControlRange   hTMLControlRange   = (IHTMLControlRange)((HTMLBody)this.ihtmldocument2_0.body).createControlRange();
         IHTMLControlElement hTMLControlElement = (IHTMLControlElement)this.ihtmldocument2_0.all.item("J_StandardCode_m", 0);
         hTMLControlRange.@add(hTMLControlElement);
         hTMLControlRange.execCommand("Copy", false, null);
         Image image = Clipboard.GetImage();
         this.pictureBoxVerify.Image = image;
         this.textBoxVerify.Focus();
         this.image_0 = image;
         (new Thread(new ThreadStart(this.method_8))).Start();
     }
     catch (Exception exception)
     {
         this.method_9(string.Concat("[inputVerifyCode]出错了!", exception.ToString()));
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// 获取验证码图片
        /// </summary>
        /// <param name="imgId"></param>
        /// <returns></returns>
        private Image GetValidateCode(string imgId)
        {
            Image               myImage = new Bitmap(60, 20);
            HtmlDocument        doc     = webBrowser1.Document;
            IHTMLControlElement img     = (IHTMLControlElement)doc.Images[imgId].DomElement;
            IHTMLDocument2      tmpDoc  = webBrowser1.Document.DomDocument as IHTMLDocument2;
            HTMLBody            body    = (HTMLBody)tmpDoc.body;
            IHTMLControlRange   rang    = (IHTMLControlRange)body.createControlRange();

            rang.add(img);
            rang.execCommand("Copy", false, null);
            myImage = Clipboard.GetImage();
            return(myImage);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 获取图像内容
        /// </summary>
        /// <param name="browser">显示图像的浏览器控件</param>
        /// <param name="imgElement">从浏览器中读取到的img</param>
        private static Image GetImage(WebBrowser browser, HtmlElement imgElement)
        {
            HTMLDocument        doc  = (HTMLDocument)browser.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(imgElement.DomElement);

            rang.add(img);
            rang.execCommand("Copy", false, null);
            Image regImg = Clipboard.GetImage();

            Clipboard.Clear();
            return(regImg);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="webCtl">WebBrowser控件</param>
        /// <param name="imgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser webBrowser, string imgeTagId)
        {
            System.Windows.Forms.HtmlDocument winHtmlDoc = webBrowser.Document;
            HTMLDocument        doc    = (HTMLDocument)winHtmlDoc.DomDocument;
            HtmlElement         imgTag = winHtmlDoc.GetElementById(imgeTagId);
            HTMLBody            body   = (HTMLBody)doc.body;
            IHTMLControlRange   rang   = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement imgE   = (IHTMLControlElement)imgTag.DomElement; //图片地址

            rang.add(imgE);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            return(numImage);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 返回指定WebBrowser中图片<IMG></IMG>中的图内容
        /// </summary>
        /// <param name="WebCtl">WebBrowser控件</param>
        /// <param name="ImgeTag">IMG元素</param>
        /// <returns>IMG对象</returns>
        private Image GetWebImage(WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument        doc  = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            Clipboard.SetImage(oldImage);
            return(numImage);
        }
Exemplo n.º 11
0
        public void GetCacheImage(WebBrowser webBrower, string id, MyDelegate myDelegate, Window window)
        {
            HTMLDocument doc  = (HTMLDocument)webBrower.Document;
            HTMLBody     body = (HTMLBody)doc.body;

            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)(doc.getElementById(id));

            rang.add(img);
            rang.execCommand("Copy", true, null);
            try
            {
                BitmapSource bitmap = Clipboard.GetImage();
                byte[]       dcimg  = ConvertToBytes(bitmap);//验证码字节码
                Clipboard.Clear();
                string result           = Dc.RecByte_A(dcimg, dcimg.Length, ConfigurationManager.AppSettings["chaorenuser"], ConfigurationManager.AppSettings["chaorenpw"], ConfigurationManager.AppSettings["softid"]);
                string verificationCode = result.Substring(0, result.IndexOf("|!|"));
                myDelegate(verificationCode);
                doc  = null;
                body = null;
                rang = null;
                img  = null;
                GC.Collect();
            }
            catch (Exception e)
            {
                Thread thr = new Thread(() =>
                {
                    string userSaveFiler = Directory.GetCurrentDirectory() + "\\weeorlog.txt";//用户账号保存文件
                    FileStream fs        = new FileStream(userSaveFiler, FileMode.OpenOrCreate);
                    StreamWriter sw      = new StreamWriter(fs);
                    sw.WriteLine(e.ToString());
                    sw.Close();
                    fs.Close();
                    //这里还可以处理些比较耗时的事情。
                    Thread.Sleep(1000);//延时2秒
                    window.Dispatcher.Invoke(new Action(() =>
                    {
                        Clipboard.Clear();
                        GetCacheImage(webBrower, id, myDelegate, window);
                    }));
                });
                thr.Start();
            }
        }
Exemplo n.º 12
0
        //讀入驗證碼
        private Image Getimage()
        {
            HTMLDocument      doc   = webBrowser1.Document.DomDocument as HTMLDocument;
            HTMLBody          body  = doc.body as HTMLBody;
            IHTMLControlRange range = body.createControlRange();
            //取得網頁中第[0]個圖片(因為我要取得的圖片的沒有ID)
            //也可使用GetElementById("ID名稱")取得圖片
            IHTMLControlElement imgElement =
                webBrowser1.Document.GetElementsByTagName("img")[0].DomElement as IHTMLControlElement;

            //複製圖片至剪貼簿
            range.add(imgElement);
            range.execCommand("copy", false, Type.Missing);
            //取得圖片
            img = Clipboard.GetImage();
            Clipboard.Clear();
            return(img);
        }
        public static Image GetRegCodePic(WebBrowser wb, HtmlElement ImgeTag)
        {
            if (ImgeTag.TagName.ToUpper() != "IMG")
            {
                return(null);
            }
            HTMLDocument        doc  = (HTMLDocument)wb.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            Clipboard.Clear();
            return(numImage);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 获取页面验证码图片转换为字符串
        /// </summary>
        /// <param name="webbrowser"></param>
        /// <returns></returns>
        public string ConImageCodeToString(System.Windows.Forms.WebBrowser webbrowser, out HtmlElement imagecodeelement)
        {
            string imagecode = default(string);

            try
            {
                #region  解析验证码
                HtmlElementCollection imageresult = webbrowser.Document.Images;
                imagecodeelement = null;
                foreach (var item in imageresult)
                {
                    HtmlElement curimg = item as HtmlElement;
                    if (curimg.OuterHtml.Contains("rand_code.csp"))
                    {
                        /*获取页面图片*/
                        imagecodeelement = curimg;
                        HTMLDocument        hdoc  = (HTMLDocument)webbrowser.Document.DomDocument;
                        HTMLBody            hbody = (HTMLBody)hdoc.body;
                        IHTMLControlRange   hcr   = (IHTMLControlRange)hbody.createControlRange();
                        IHTMLControlElement hImg  = (IHTMLControlElement)curimg.DomElement;
                        hcr.add(hImg);
                        hcr.execCommand("Copy", false, null);
                        Image  CodeImage = Clipboard.GetImage();
                        Bitmap bitmap    = new Bitmap(CodeImage);
                        /*******解析验证码********/
                        BreakCodeServer unCheckobj = new BreakCodeServer(bitmap);
                        Thread.Sleep(2000);
                        imagecode = unCheckobj.getPicnum();
                        break;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                SetText(System.DateTime.Now.ToString() + "\r\n解析验证码失败\r\n");
                imagecodeelement = null;
                imagecode        = "";
            }
            return(imagecode);
        }
Exemplo n.º 15
0
        private System.Drawing.Image GetWebImage(System.Windows.Forms.WebBrowser WebCtl, HtmlElement ImgeTag)
        {
            HTMLDocument        doc  = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            var oldImage = System.Windows.Forms.Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            var numImage = System.Windows.Forms.Clipboard.GetImage();

            try
            {
                System.Windows.Forms.Clipboard.SetImage(oldImage);
            }
            catch
            {
            }

            return(numImage);
        }
Exemplo n.º 16
0
        private void TestTuring()
        {
            IHTMLDocument2        doc           = (IHTMLDocument2)webBrowser.Document.DomDocument;
            HtmlElementCollection imgCollection = webBrowser.Document.GetElementsByTagName("img");
            IHTMLControlRange     imgRange      = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
            int i = 0;

            foreach (HtmlElement img in imgCollection)
            {
                IHTMLControlElement cimg = img.DomElement as IHTMLControlElement;
                if (cimg != null)
                {
                    imgRange.add(cimg);
                    imgRange.execCommand("Copy", false, null);
                    using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                    {
                        var imgName = "img" + i + ".gif";
                        bmp.Save(imgName);
                        i++;
                    }
                }
            }
        }
Exemplo n.º 17
0
        private Bitmap GetVerificationImage()
        {
            Bitmap result = null;
            var    id     = ConfigurationManager.AppSettings["ImgId"];

            HTMLDocument        html  = (HTMLDocument)this.webBrowser1.Document.DomDocument;
            IHTMLControlElement img   = (IHTMLControlElement)webBrowser1.Document.Images[id].DomElement;
            IHTMLControlRange   range = (IHTMLControlRange)((HTMLBody)html.body).createControlRange();

            range.add(img);
            range.execCommand("Copy", false, null);

            if (Clipboard.ContainsImage())
            {
                result = new Bitmap(Clipboard.GetImage());
            }
            else
            {
                MessageBox.Show("获取验证码失败");
            }

            Clipboard.Clear();
            return(result);
        }
Exemplo n.º 18
0
        public override object getVerCodeImage(HtmlDocument indoc)
        {
            HTMLDocument doc = (HTMLDocument)indoc.DomDocument;

            if (doc == null)
            {
                return(doc);
            }
            //Image img = null;
            HtmlElement ImgeTag = indoc.GetElementById("img-valcode");

            //mshtml.IHTMLElementCollection
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img  = (IHTMLControlElement)ImgeTag.DomElement; //图片地址
            object oldobj            = Clipboard.GetDataObject();               //备份粘贴版数据

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            rang = null;
            return(numImage);
        }
Exemplo n.º 19
0
        public static Image GetWebImage_test(WebBrowser WebCtl, string doucmentName)
        {
            HtmlElement         ImgeTag = WebCtl.Document.All[doucmentName];
            HTMLDocument        doc     = (HTMLDocument)WebCtl.Document.DomDocument;
            HTMLBody            body    = (HTMLBody)doc.body;
            IHTMLControlRange   rang    = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement Img     = (IHTMLControlElement)ImgeTag.DomElement; //图片地址

            Image oldImage = Clipboard.GetImage();

            rang.add(Img);
            rang.execCommand("Copy", false, null);  //拷贝到内存
            Image numImage = Clipboard.GetImage();

            try
            {
                Clipboard.SetImage(oldImage);
            }
            catch
            {
            }

            return(numImage);
        }
Exemplo n.º 20
0
        public string getVimg(HtmlDocument document, string vimgID)
        {
            HtmlElement         vimg = document.GetElementById(vimgID);
            HTMLDocument        doc  = (HTMLDocument)document.DomDocument;
            HTMLBody            body = (HTMLBody)doc.body;
            IHTMLControlRange   rang = (IHTMLControlRange)body.createControlRange();
            IHTMLControlElement img  = (IHTMLControlElement)vimg.DomElement;

            try
            {
                Image oldImage = Clipboard.GetImage();
                rang.add(img);
                rang.execCommand("Copy", false, null);
                Image numImage = Clipboard.GetImage();
                Clipboard.SetImage(oldImage);
                using (Page page = engine.Process(new Bitmap(numImage)))
                {
                    return(page.GetText());
                }
            }catch (Exception ex)
            {
                return("");
            }
        }
Exemplo n.º 21
0
        protected override async void OnDocumentCompleted(string html, string url)
        {
            Application.DoEvents();
            var doc = (HTMLDocument)WB.Document.DomDocument;

            //var winList = GetAllWindow(WB.Document.Window);
            if (WB.Document.Title == "导航已取消" || WB.Document.Title == "无法显示此页")
            {
                return;
            }

            HtmlElement J_Message = WB.Document.All["J_Message"];

            if (J_Message != null && !string.IsNullOrEmpty(J_Message.InnerText))
            {
                return;
            }
            if (html.IndexOf("secondVerifyRender();") != -1)
            {
                return;
            }
            if (html.IndexOf("auther('true')") != -1)
            {
                IHTMLControlElement button = (IHTMLControlElement)doc.getElementById("sub");
                if (button.clientHeight > 0)
                {
                    //自动点击授权按钮
                    WB.Document.InvokeScript("auther", new object[] { "true" });
                    return;
                }
            }
            if (url.IndexOf("https://login.taobao.com/member/login.jhtml") != -1)
            {
                try
                {
                    IHTMLControlElement J_QuickLogin = (IHTMLControlElement)doc.getElementById("J_QuickLogin");
                    IHTMLControlElement J_Static     = (IHTMLControlElement)doc.getElementById("J_Static");
                    var body = doc.getElementsByTagName("body").AsList <IHTMLControlElement>()[0];
                    if (J_Static == null)
                    {
                        //可能遇到了javascript跳转逻辑
                        return;
                    }
                    WB.Document.All["J_SubmitStatic"].Click += WBTaoLoginState_Click;
                    await Task.Delay(100);

                    if (J_Static.clientWidth > 0 && J_Static.clientHeight > 0)
                    {
                        IsPasswordLogin = true;
                        StaticLogin(doc);
                    }
                    else if (J_QuickLogin.clientWidth > 0 && J_QuickLogin.clientHeight > 0)
                    {
                        IsPasswordLogin = false;
                        //<span class="title">检测到您已经登录的账户:</span>
                        //<form action = "" >
                        //    < input name="redirectURL" id="el_redirectURL" type="hidden" value="http://www.taobao.com">
                        //    <ul class="userlist">
                        //    <li class="item-sso-user current"><input name = "user" class="r-sso-user r-wwuser" id="ra-0" type="radio" checked="" value="cntaobaocendart" data-type="ww" data-index="0"> <label for="ra-0">cendart</label></li></ul>
                        //    <div class="submit">
                        //        <button id = "J_SubmitQuick" type="submit">快速登录</button>
                        //    </div>
                        //    <ul class="entries">
                        //    <li><a class="module-switch" id="J_Quick2Static" href="#" data-target="static">使用其他账户登录</a></li>
                        //      </ul>
                        //</form>
                        var current = WB.Document.Body.JQuerySelect("#J_QuickLogin .userlist .current label");
                        var xdoc    = new Nx.EasyHtml.Html.Parser.JumonyParser().Parse(WB.Document.Body.InnerHtml, WB.Document.Url);
                        var label   = xdoc.FindFirst(".current label");
                        if (current.Any())
                        {
                            if (AppSetting.UserSetting != null)
                            {
                                //使用其他账户登录
                                WB.Document.All["J_Quick2Static"].InvokeMember("click");
                                StaticLogin(doc);
                            }
                            else
                            {
                                var nick = current[0].InnerText;
                                InitAppUserSetting(nick);
                                if (!string.IsNullOrEmpty(AppSetting.UserSetting.Get <string>("TaoUserName")))
                                {
                                    if (nick == AppSetting.UserSetting.Get <string>("TaoUserName"))
                                    {
                                        if (AppSetting.UserSetting.Get <bool>("AutoSelectLoginedAccount"))
                                        {
                                            WB.Document.All["J_SubmitQuick"].InvokeMember("click");
                                        }
                                    }
                                    else
                                    {
                                        //使用其他账户登录
                                        WB.Document.All["J_Quick2Static"].InvokeMember("click");
                                        StaticLogin(doc);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            if (html.IndexOf("选择其中一个已登录的账户") != -1)
            {
                //帮着点了
                WB.Document.All["J_SubmitQuick"].InvokeMember("click");
            }
            if (url.StartsWith(AuthorizedUrl))
            {
                if (url != AuthorizedUrl)
                {
                    WB.Navigate(AuthorizedUrl);
                }
            }
            if (url.StartsWith("http://container.api.taobao.com/container") && WB.DocumentTitle == "错误页面")
            {
                AppSetting.UserSetting.SetNull("AutoSelectLoginedAccount");
            }
        }
Exemplo n.º 22
0
        private void btn_fillone_Click(object sender, EventArgs e)
        {
            if ("http://cwpt.suda.edu.cn/WFManager/login.jsp" != webBrowser1.Url.ToString())
            {
                MessageBox.Show("不正确的页面, 不要乱用功能!");
            }
            else if (username == "" || password == "")
            {
                MessageBox.Show("用户名或密码不完整!");
                return;
            }
            else
            {
                //根据验证码ID获取验证码元素
                HtmlElement ImageCodeTag = webBrowser1.Document.GetElementById("checkcodeImg");
                //获取网页所有内容
                HTMLDocument hdoc = (HTMLDocument)webBrowser1.Document.DomDocument;
                //获取网页body标签中的内容
                HTMLBody hbody = (HTMLBody)hdoc.body;
                //创建一个接口
                IHTMLControlRange hcr = (IHTMLControlRange)hbody.createControlRange();
                //获取图片地址
                IHTMLControlElement hImg = (IHTMLControlElement)ImageCodeTag.DomElement;
                //将图片添加到接口中
                hcr.add(hImg);
                //将图片复制到内存
                hcr.execCommand("Copy", false, null);
                //从粘贴板得到图片
                Image CodeImage = Clipboard.GetImage();
                //返回得到的验证码
                //CodeImage.Save("123.png");

                // 识别验证码
                byte[]        Buffer     = ImageToBytes(CodeImage);
                StringBuilder Result     = new StringBuilder('\0', 256);
                string        coderesult = "";
                if (GetImageFromBuffer(Buffer, Buffer.Length, Result))
                {
                    coderesult = Result.ToString();
                }
                else
                {
                    coderesult = "识别失败";
                }

                //填充用户名密码验证码
                HtmlElement name = webBrowser1.Document.GetElementById("uid");
                if (name != null)
                {
                    name.SetAttribute("value", username);
                }
                HtmlElement pass = webBrowser1.Document.GetElementById("pwd");
                if (pass != null)
                {
                    pass.SetAttribute("value", password);
                }
                HtmlElement code = webBrowser1.Document.GetElementById("chkcode");
                if (code != null)
                {
                    code.SetAttribute("value", coderesult);
                }

                HtmlElement loginbtn = webBrowser1.Document.GetElementById("loginbtn2");
                if (loginbtn != null)
                {
                    loginbtn.InvokeMember("click");
                }
            }
        }
Exemplo n.º 23
0
        public void SelectControlElement(IHTMLControlElement controlElement)
        {
            using (new InitialInsertionNotify(this))
            {
                // see if the image is already selected
                IHTMLElement selectedControl = ((IHtmlEditorComponentContext)this).Selection.SelectedControl;
                if (selectedControl != null)
                    if (Marshal.GetIUnknownForObject(controlElement) == Marshal.GetIUnknownForObject(selectedControl))
                        return;

                // select the image
                IHTMLTextContainer textContainer = HTMLDocument.body as IHTMLTextContainer;
                IHTMLControlRange controlRange = textContainer.createControlRange() as IHTMLControlRange;
                controlRange.add(controlElement);
                UpdateSelection(controlRange);
            }
        }