Delphi 如何提取WebBrowser里的图片?
procedure 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;
procedure TForm1.WebBrowser1DocumentComplete(Sender:TObject;
const pDisp:IDispatch;var URL:OleVariant);
begin
DomImg2Image('checkcode?',TWebBrowser(Sender),Image1);
end;
必须先uses ActiveX
initialization
OleInitialize(nil);
finalization
OleUninitialize;
//多看几篇就懂了,关键还是这个接口 IHTMLControlElement

浙公网安备 33010602011771号