zoukankan      html  css  js  c++  java
  • 提取验证码到winform上webbroswer和axwebbroswer

    在网上只有webbroswer的代码,所以自己又修改了修改改成axwebbroswer的

    public static class yanZhengMaHelp
        {
            //webbrowser验证码
            public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt)
            {
                HTMLDocument doc = (HTMLDocument)wbMail.Document.DomDocument;
                HTMLBody body = (HTMLBody)doc.body;
                IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement Img;
                if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
                {
                    int ImgNum = GetPicIndex(wbMail, Src, Alt);
                    if (ImgNum == -1)
                    {
                        return null;
                    }
                    Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;
                }
                else
                    Img = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement;
    
                rang.add(Img);
                rang.execCommand("Copy", false, null);
                Image RegImg = Clipboard.GetImage();
                Clipboard.Clear();
                return RegImg;
            }
    
            public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt)
            {
                int imgnum = -1;
                for (int i = 0; i < wbMail.Document.Images.Count; i++) //获取所有的Image元素
                {
                    IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;
                    if (Alt == "")
                    {
                        if (img.src.Contains(Src)) return i;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(img.alt))
                        {
                            if (img.alt.Contains(Alt)) return i;
                        }
                    }
                }
                return imgnum;
            }
            //axwebbroswer 验证码  提取
            public static Image GetRegCodePic(AxWebBrowser axwbMail, string ImgName, string Src, string Alt)
            {
               
                HTMLDocument doc = (HTMLDocument)axwbMail.Document;
                HTMLBody body = (HTMLBody)doc.body;
                IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();
                IHTMLControlElement Img;
                if (ImgName == "") //如果没有图片的名字,通过Src或Alt中的关键字来取
                {
                    Img = (IHTMLControlElement)GetPicIndex(axwbMail, Src, Alt);
                    if (Img == null)
                    {
                        return null;
                    }
    
    
                }
                else
                {
                    Img = (IHTMLControlElement)doc.getElementsByName(ImgName).item(null, 0);
                }
    
                rang.add(Img);
                rang.execCommand("Copy", false, null);
                Image RegImg = Clipboard.GetImage();
                Clipboard.Clear();
                return RegImg;
            }
            public static IHTMLImgElement GetPicIndex(AxWebBrowser axwbMail, string Src, string Alt)
            {
    
                HTMLDocument doc = (HTMLDocument)axwbMail.Document;
    
                foreach (IHTMLImgElement img in (IHTMLElementCollection)doc.getElementsByTagName("img")) //获取所有的Image元素
                {
    
                    if (Alt == "")
                    {
                        if (img.src.Contains(Src)) return img;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(img.alt))
                        {
                            if (img.alt.Contains(Alt)) return img;
                        }
                    }
                }
                return null;
    
            }
  • 相关阅读:
    HDU 5514 Frogs 欧拉函数
    HDU 5521 Meeting 最短路
    HDU 5527 Too Rich 贪心
    HDU 5525 Product 数论
    MFC中 编辑框内组合键的使用
    MyEclipse+Struts+Hibernate+Mysql开发环境配置
    SSH框架介绍
    mysql忘记密码的解决办法
    VS2010 MFC中 窗口分割的实现
    VS2010 MFC中 创建文件夹及文件判空的方法
  • 原文地址:https://www.cnblogs.com/weiwin/p/3868576.html
Copyright © 2011-2022 走看看