下面是提取图片的代码 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; |
联系客服