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;
    
            }
  • 相关阅读:
    echarts 算百分比与js toFixed算出来的百分比不一致的问题。
    VUE, Vue Router Tab 显示动态页签名称。
    [日常坑]前端j's数据导出excel,导出的文件损坏
    [最新 | Build 3211]Sublime Text 2.x, 3.x 许可License集合
    图片滤波
    electron-ipc通信性能分析
    设计vue3的请求实体工厂
    canvas-修改图片亮度
    canvas性能-drawImage渲染图片
    基于windows配置gitlab-runner
  • 原文地址:https://www.cnblogs.com/weiwin/p/3868576.html
Copyright © 2011-2022 走看看