一个成功获取百度注册页面验证码图片的源代码
2012-10-12 12:58
399 查看
成功实现使用delphi获取百度的验证码图片(只获得图片,不进行识别,识别之后再研究吧O(∩_∩)O)
用到的控件:TWebBrowser、IDhttp、IdSSLIOHandlerSocketOpenSSL还有一个image负责显示验证码图片。
需要使用两个dll包。delphi2007的可以使用的连接地址为:http://download.csdn.net/detail/sushengmiyan/4639225
procedure TForm1.btn1Click(Sender: TObject); procedure doSomething(ms: TMemoryStream); var Buffer:Word; AjpgFile: TJPEGImage; begin ms.Position := 0; if ms.Size = 0 then Exit; ms.ReadBuffer(Buffer,2); //读取文件的前2个字节,放到Buffer里面 if Buffer=$4D42 then //如果前两个字节是以4D42[低位到高位] begin ShowMessage('BMP'); //那么这个是BMP格式的文件 end else if Buffer=$D8FF then //如果前两个字节是以D8FF[低位到高位] begin ShowMessage('JPEG'); //........一样 下面不注释了 ms.Position := 0; AjpgFile := TJPEGImage.Create; AjpgFile.LoadFromStream(ms); Image1.Picture.Graphic := AjpgFile; end else if Buffer=$4947 then begin ShowMessage('GIF'); end else if Buffer=$5089 then begin ShowMessage('PNG'); end; end; var Openurl : string; elem: IHTMLElement; coll: IHTMLElementCollection; i: Integer; url, Text: string; d2,D:IHTMLDocument2; d1:IHTMLDocument; e:IHTMLElement; e2:IHTMLElement2; cp: IHTMLControlRange; img:IHTMLImgElement; ce:IHTMLControlElement; bmp:TBitmap ; r0:TRect; newbmp:TBitmap; r1:TRect; checkstr:string; MyHandle :THandle ; bmpPtr:Pointer; ms:TMemoryStream; //内存流对象 begin ms := TMemoryStream.Create; //建立内存流对象 IdHTTPBaiDu := TIdHTTP.Create(nil); IdHTTPBaiDu.ReadTimeout := 2000000; IdHTTPBaiDu.IOHandler := IdSSLIOHandlerSocketOpenSSL1.Create(nil); Openurl := 'https://passport.baidu.com/v2/?reg&u=http://www.baidu.com/&tpl=mn'; // Openurl := 'http://zc.qq.com/chs/index.html'; // Openurl := 'http://www.doubao.com/user/reg';//豆包网 try BaiDuWebBrowser.Navigate(Openurl); while BaiDuWebBrowser.Busy do begin Application.ProcessMessages; end; BaiDuWebBrowser.Stop; if BaiDuWebBrowser.Document = nil then Exit; //获取源代码 D := BaiDuWebBrowser.Document as IHTMLDocument2; e :=d.body as IHTMLElement; e2 :=e as IHTMLElement2; cp :=e2.createControlRange as IHTMLControlRange; d2 :=BaiDuWebBrowser.Document as IHTMLDocument2; //下面是破解验证码 coll := d.all; coll :=(coll.tags('img') as IHTMLElementCollection); for i := 0 to coll.Length - 1 do begin //循环取出每个url elem := (coll.item(i,0) as IHTMLElement); url :=Trim(string(elem.getAttribute(WideString('src'), 0))); //Text := Trim(string(elem.outertext)); if Pos('doubao' , url) > 0 then //豆包网 begin if Pos('auth/checkcode',url) > 0 then begin IdHTTPBaiDu.Get(url,ms); doSomething(ms); Break; end end else if Pos('qq.com' , url) > 0 then //腾讯QQ begin if pos('getimage', url) > 0 then begin IdHTTPBaiDu.Get(url,ms); doSomething(ms); Break; end end else if Pos('baidu.com' , url) > 0 then //百度 begin if Pos('genimage',url) > 0then begin IdHTTPBaiDu.Get(url,ms); doSomething(ms); Break; end; end; end; finally end; end;写的很烂,不过确实可以实现。嘻嘻~
用到的控件:TWebBrowser、IDhttp、IdSSLIOHandlerSocketOpenSSL还有一个image负责显示验证码图片。
需要使用两个dll包。delphi2007的可以使用的连接地址为:http://download.csdn.net/detail/sushengmiyan/4639225
相关文章推荐
- tornado web高级开发项目之抽屉官网的页面登陆验证、form验证、点赞、评论、文章分页处理、发送邮箱验证码、登陆验证码、注册、发布文章、上传图片
- android开发之获取一个页面的源代码用一个textview显示出来
- 一个页面如何放多个百度编辑器 Ueditor 1.4.3?PHP如何获取Ueditor 的值?
- 我写的一个从百度服务器获取应答的程序_本来想获取百度首页的源代码的
- selenium2java 一个利用mysql获取验证码注册新用户的测试用例
- Android 注册页面 设置显示或者隐藏密码 和 点击获取验证码倒计时60s
- php 根据给定的一个查询关键字,获取百度的相关关键字,多个页面获取,非单页的相关搜索
- delphi用内存流方式获取页面验证码图片
- 第57篇一对多实现之私有白板向老师端传图片数据(四)新建一个iframe及成功获取私有白板数据 周日
- 如何在注册页面,获取验证码的值。
- 注册登录页面的获取验证码倒计时
- android一个注册页面和验证码的实现
- 注册页面获取验证码
- H5写一个百度搜索页面 源代码
- 用struts标签完成一个注册页面
- 百度IFE学习笔记(三)js获取页面内容及后续处理
- html5 实现网页截屏 页面生成图片(源代码)
- php $_SERVER['HTTP_REFERER']获取上一个页面的URL地址
- html实现一个完整的注册页面
- 一个小的验证码图片生成程序