分享

怎么读取网页验证码的图片(1)

 独孤求财 2012-05-17
怎么读取网页验证码的图片(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;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多