Шустрый

Профиль
Группа: Участник
Сообщений: 58
Регистрация: 1.4.2009
Репутация: нет Всего: нет
|
Подскажите как правильно прикрутить антикапчу, первый раз с ней столкнулся куда этот код нужно вставить? Код | procedure TForm1.Button1Click(Sender: TObject); Var tr : TstringList; s,t,sres:string; Captcha:TMemoryStream;
begin tr:=TstringList.Create; tr.Add('username=LOGIN'); tr.Add('password=PASS'); idhttp1.Post('http://www.sait/auth.php?action=doauth',tr);
s:=idHTTP1.Get('http://www.sait/map.php'); sres:=copy(s,pos('profile ',s)+72,length(s)-pos('profile ',s)+72); sres:=copy(sres,2,pos('</a>',sres)); sres:=copy(sres,1,length(sres)-10);
captcha:=TMemoryStream.Create; idhttp1.Get('http://www.sait/code.php?id='+sres,captcha); captcha.SaveToFile('captcha.png'); Captcha.Free; tr.Free;
s:=idHTTP1.Get('http://www.sait/rad.php'); sres:=copy(s,pos('123',s)+200,length(s)-pos('123',s)+200); sres:=copy(sres,2,pos('44',sres)); sres:=copy(sres,1,length(sres)-85); idhttp1.Get('http://www.sait/index.php?hte=work&id='+sres+'&code='+result); // сюда нужно отправить текст отгаданной капчи
|
КОД АНТИКАПЧИ Код | implementation
{$R *.dfm} function recognize(filename: string; apikey: string; is_phrase: boolean; is_regsense: boolean; is_numeric: boolean; min_len: integer; max_len: integer): string; var ftype,tmpstr,captcha_id: String; i: integer; http: TIdHTTP; multi: Tidmultipartformdatastream; begin if FileExists(filename)=false then begin result:='ERROR: file not found'; exit; end;
ftype:='image/pjpeg'; if strpos(Pchar(filename),'jpg')<>nil then ftype:='image/pjpeg'; if strpos(Pchar(filename),'gif')<>nil then ftype:='image/gif'; if strpos(Pchar(filename),'png')<>nil then ftype:='image/png';
multi:=Tidmultipartformdatastream.Create; multi.AddFormField('method','post'); multi.AddFormField('key',apikey); multi.AddFile('file',filename,ftype); if is_phrase=true then multi.AddFormField('phrase','1'); if is_regsense=true then multi.AddFormField('regsense','1'); if is_numeric=true then multi.AddFormField('numeric','1'); if min_len>0 then multi.AddFormField('min_len',inttostr(min_len)); if max_len>0 then multi.AddFormField('max_len',inttostr(max_len));
http:=TIdHTTP.Create(nil); tmpstr:=http.Post('http://anti-captcha.com/in.php',multi); http.Free; captcha_id:=''; if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end; if strpos(Pchar(tmpstr),'OK|')<>nil then captcha_id:=AnsiReplaceStr(tmpstr,'OK|',''); if captcha_id='' then result:='ERROR: bad captcha id'; for i:=0 to 20 do begin Application.ProcessMessages; sleep(5000); http:=TIdHttp.Create(nil); tmpstr:=http.Get('http://anti-captcha.com/res.php?key='+apikey+'&action=get&id='+captcha_id); http.Free; if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end; if strpos(Pchar(tmpstr),'OK|')<>nil then begin result:=AnsiReplaceStr(tmpstr,'OK|',''); exit; end; Application.ProcessMessages; end; result:='ERROR_TIMEOUT';
end;
procedure TForm1.Button1Click(Sender: TObject); begin
rsltedit.Text:='recognizing...'; Button1.Enabled:=false; rsltedit.Text:=recognize(filenameedit.Text,apikeyedit.Text,false,false,false,0,0); Button1.Enabled:=true; end;
end.
|
|