天天看點

delphi webbrowser 擷取驗證碼

use

clipbrd , mshtml

procedure TForm1.DomImg2Image(src:string;wb:TWebBrowser;img:TImage);

var

  i:Integer;

  rang:IHTMLControlRange;

begin

  for i:=0 to IHTMLDocument2(wb.Document).images.length-1 do

    if Pos(src,(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as

      IHTMLElement).getAttribute('src',0))>0 then

    begin

      rang:=((IHTMLDocument2(wb.Document).body as HTMLBody).createControlRange)as

        IHTMLControlRange;

      rang.add(IHTMLDocument2(wb.Document).images.item(i,EmptyParam)as

        IHTMLControlElement);

      rang.execCommand('Copy',False,0);

      try img.Picture.Assign(ClipBoard)except end;

      break;

    end;

end;

DomImg2Image('CheckCode?',wb1,img1);

繼續閱讀