有一个Form1,里面有image1和webBrowser1,我用WebBrowser1连接到一个有验证码的网页,想把里面的图片提取到image1里,应该怎么做? 问题补充: 我指的是图片。例如:http://china.alibaba.com/member/join.htm验证码的地址是: http://checkcode.china.alibaba.com/service/checkcode?sessionID=e9EgR8RbEt2F8k68tQGjCKJ9NZnf8%24cS那里的图片是每次都变化的。我需要的是把WebBrowser里显示的验证码加载到TImage的对象里。下面的图像如果看不清,就看这个链接:http://hiphotos.baidu.com/neek/pic/item/a4c5f0d3804a83fca9ec9ac3.jpeg 最佳答案: 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; 还要加一个单元文件 clipbrd 和 mshtml。
|