idhttp或者webbrowser
webbrowser比较简单点,但是效率不高
获取验证码:
procedure TForm1.getimg;
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
while Form1.wb1.Busy do
Application.ProcessMessages;
Form1.wb1.Stop;
if Form1.wb1.Document = nil then Exit;
//Memo1.Lines.Add(IHTMLDocument2(WebBrowser1.Document).Body.OuterHtml) ; //获取源代码
D:= Form1.wb1.Document as IHTMLDocument2;
e:=d.body as IHTMLElement;
e2:=e as IHTMLElement2;
cp:=e2.createControlRange as IHTMLControlRange;
d2:= Form1.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);
Form1.img1.Picture.Bitmap.Assign(Clipboard);
Form1.img1.Picture.LoadFromClipboardFormat(cf_BitMap,MyHandle,0);
Clipboard.Clear;
GlobalUnlock(MyHandle);
finally
Clipboard.Close;
end;
end;
bmp:=(Form1.img1.Picture.Bitmap as TBitmap) ;
//checkstr:=getCheckStr(bmp);
except
Form1.img1.Picture.LoadFromClipboardFormat(cf_BitMap,ClipBoard.GetAsHandle(cf_Bitmap),0);
checkstr :='';
// Form1.img1.Tag:=1;
end;
finally
//
end;
end;