在网上只有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 == -)
{
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 = -;
for (int i = ; 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, );
} 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; }

提取验证码到winform上webbroswer和axwebbroswer的更多相关文章

  1. WinForm上显示gif动画:转

    WinForm上的ProgressBar,老实说,实在是不敢恭维,太死板,太难看了,即使做成实时显示处理进度的,它还是逃离不了“难看”.现 在的web2.0上到处都能看到一个显示正在处理的小圆圈在那转 ...

  2. winform 上传文件

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  3. Excel催化剂开源第29波-在Winform上使用富文本编辑器控件

    富文本编辑器,一般都是BS架构专利一般,好像百度有一个开源的比较出名,但无奈这些都只能用在JS上,在BS网页端开发上使用.像Winform开发的VSTO,只能羡慕的份.和一般Winform上用的Ric ...

  4. ThinkPHP讲解(十一)——验证码和文件上传

    一.验证码 1.页面前端显示 (验证码是图片标签,来源是控制器里的yzm()操作方法) <h1>登录</h1> <form action="__ACTION__ ...

  5. C# winform 上传文件到服务器

    1.首先要在服务器端新建一个网站axpx页 然后再网站的后台写代码获取winform传过来的文件名. 声明:这个方法虽然最简单最省事,但是上传大文件可能会报错,我的机器是10M, 超过10M就会提示报 ...

  6. Winform上传下载文件代码

    using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO ...

  7. Thinkphp 验证码、文件上传

    一.验证码 验证码参数 例题:登录时验证下验证码 LoginController.class.php <?php namespace Home\Controller; use Think\Con ...

  8. 快速提取PROTEL99SE PCB文件上的封装方法

    1.首先打开你要提取元件封装的PCB. 2.执行生成元件库的命令...软件会帮你把这个PCB上的所有元件生成一个临时库. 3.打开你自己的元件库... 4.PCB刚才生成的元件库中选中你所需要的元件, ...

  9. PHP之ThinkPHP框架(验证码、文件上传、图片处理)

     验证码 验证码是框架自带有的,比之前使用GD库简单方便许多,其实现原理基本相似,都是生成图片,保存验证码值到Session中,表单提交验证码,然后进行值的对比验证. 简单的显示: <form ...

随机推荐

  1. Python 模块化 from .. import 语句资源搜索顺序 (三)

    接着上一篇文章最后的import子句资源搜索顺序,我们来写几个例子了解下. 例一. #test1.py x = 123 #test.py import test1 print(dir()) print ...

  2. Microsoft visual c++ 14.0 is required问题

    错误信息: error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Too ...

  3. Tomcat中的Filter

    Filter 节选部分源码.源码版本 Tomcat8.5 说明 filter 是 Servlet 规范 filter 是在 ,执行 Servlet.service方法之前执行 Filter相关接口 p ...

  4. arcgis js api proxy java 版本配置

    <?xml version="1.0" encoding="utf-8" ?> <ProxyConfig allowedReferers=&q ...

  5. keepalived 的进程/usr/sbin/keepalived -D 只有2个

    操作系统:openSUSE 11.3 (x86_64) /usr/sbin/keepalived -D  只有2条 日志:ls  /var/log/messages* -lrth Can't init ...

  6. C#中调用方法

    using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...

  7. 使用XWAF框架(1)——Web项目的代码分层

    建议在Eclipse环境下使用XWAF框架来开发用户的Web项目,并遵循以下步骤和约定. 1.获取XWAF框架压缩包文件 程序员点击下列地址免费下载XWAF框架的压缩包文件:XWAF框架压缩文件 2. ...

  8. iOS:时间相关(18-10-13更)

    先整理出时间相关的程序,以后有空再写成单例. 1.日历(NSCalendar) 2.时间格式() 3.时间戳 附录: 1.定时器 1.日历(NSCalendar) 1.想要获取 世纪.年.月.日.时. ...

  9. C++较精确的测试代码运行时间

    #include <chrono> using namespace chrono; int main() { auto t0 = system_clock::now(); //测试代码 a ...

  10. 运行Delphi XE10的MongoDB例程,测试Delphi插入记录性能

    Delphi XE10支持MongoDB的数据库,提供了个例子restaurants可批量导入数据. 本文对比Delphi例子与MongoDB自带的mongoimport导入批量数据的性能. 步骤: ...