|
有一個Form1,里面有image1和webBrowser1,我用WebBrowser1連接到一個有驗證碼的網(wǎng)頁,想把里面的圖片提取到image1里,應(yīng)該怎么做? 問題補充: 我指的是圖片。例如: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。
|