打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
怎么读取网页验证码的图片(1)
怎么读取网页验证码的图片(1)
2009年07月03日 星期五 13:29
下面是提取图片的代码
var elem: IHTMLElement;              //     使用需     uses Mshtml,SHDocVw;
   coll: IHTMLElementCollection;     //    mshtm类
   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;
begin
try
   Result := '3';
   //if (PostText = '') then Exit;
    // btn4Click(btn4);
   wb1.Navigate(Openurl);

   while wb1.Busy do
   Application.ProcessMessages;
   wb1.Stop;


   if wb1.Document = nil then Exit;
      //Memo1.Lines.Add(IHTMLDocument2(WebBrowser1.Document).Body.OuterHtml) ; //获取源代码

     D:=   wb1.Document   as   IHTMLDocument2;
    e:=d.body   as   IHTMLElement;
    e2:=e   as   IHTMLElement2;
    cp:=e2.createControlRange   as   IHTMLControlRange;
    d2:=   wb1.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('getCheckImg', url) >0 then
            begin
             
               Break;
            end;
          //DebugInfo(text+#13#10+url) ;
         Application.ProcessMessages;
      end;
    img:=elem   as      IHTMLImgElement;
    ce:=img   as   IHTMLControlElement;
    cp.add(ce);
    try
     // Clipboard.Open;
     Clipboard.Clear;
     // if   Clipboard.hasFormat(CF_BITMAP) then
      begin

      try
      cp.execCommand('Copy',false,0);
       MyHandle := Clipboard.GetAsHandle(cf_Bitmap);
        bmpPtr := GlobalLock(MyHandle);
        img1.Picture.Bitmap.Assign(Clipboard);
        img1.Picture.LoadFromClipboardFormat(cf_BitMap,MyHandle,0);
         Clipboard.Clear;
        GlobalUnlock(MyHandle);
      finally
        Clipboard.Close;
      end;
      end;
    bmp:=(img1.Picture.Bitmap as TBitmap) ;
    checkstr:=getCheckStr(bmp);
    except

      img1.Picture.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
      checkstr :='';
    end;
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
如何取得网页框架中的内容(300分)
delphi WebBrowser 点击任意元素 或图片
delphi 模拟自动登录网页
使用Webbrowser的一点心得体会--seimd的时空博客
VC 剪贴板操作_knightzwy
Clipboard Extention
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服