Сейчас на форуме: 2nd, morgot, Rio, CDK123, zds, tyns777, tihiy_grom (+5 невидимых)

 eXeL@B —› Программирование —› Проблема с настройкой anti-captcha
Посл.ответ Сообщение

Ранг: 12.8 (новичок)
Активность: 0.010
Статус: Участник

Создано: 01 апреля 2009 23:52
· Личное сообщение · #1

Подскажите как правильно прикрутить антикапчу, первый раз с ней столкнулся
куда этот код нужно вставить?

Code:
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. Var
  3.  tr : TstringList;
  4.  s,t,sres:string;
  5.  Captcha:TMemoryStream;
  6. begin
  7. tr:=TstringList.Create;
  8. tr.Add('username=LOGIN');
  9. tr.Add('password=PASS');
  10. idhttp1.Post('http://www.sait/auth.php?action=doauth',tr);
  11. s:=idHTTP1.Get('http://www.sait/map.php');
  12. sres:=copy(s,pos('profile ',s)+72,length(s)-pos('profile ',s)+72);
  13. sres:=copy(sres,2,pos('</a>',sres));
  14. sres:=copy(sres,1,length(sres)-10);
  15. captcha:=TMemoryStream.Create;
  16. idhttp1.Get('http://www.sait/code.php?id='+sres,captcha);
  17. captcha.SaveToFile('captcha.png');
  18. Captcha.Free;
  19. tr.Free;
  20. s:=idHTTP1.Get('http://www.sait/rad.php');
  21. sres:=copy(s,pos('123',s)+200,length(s)-pos('123',s)+200);
  22. sres:=copy(sres,2,pos('44',sres));
  23. sres:=copy(sres,1,length(sres)-85);
  24. idhttp1.Get('http://www.sait/hte=work&id='+sres+'&code='+res ult); // сюда нужно отправить текст отгаданной капчи


КОД АНТИКАПЧИ

Code:
  1. implementation
  2. {$*.dfm}
  3. function recognize(filename: string; apikey: string; is_phrase: boolean; is_regsense: boolean; is_numeric: boolean; min_len: integer; max_len: integer): string;
  4. var
  5. ftype,tmpstr,captcha_id: String;
  6. i: integer;
  7. http: TIdHTTP;
  8. multi: Tidmultipartformdatastream;
  9. begin
  10. if FileExists(filename)=false then begin result:='ERROR: file not found'; exit; end;
  11. ftype:='image/pjpeg';
  12. if strpos(Pchar(filename),'jpg')<>nil then ftype:='image/pjpeg';
  13. if strpos(Pchar(filename),'gif')<>nil then ftype:='image/gif';
  14. if strpos(Pchar(filename),'png')<>nil then ftype:='image/png';
  15. multi:=Tidmultipartformdatastream.Create;
  16. multi.AddFormField('method','post');
  17. multi.AddFormField('key',apikey);
  18. multi.AddFile('file',filename,ftype);
  19. if is_phrase=true then multi.AddFormField('phrase','1');
  20. if is_regsense=true then multi.AddFormField('regsense','1');
  21. if is_numeric=true then multi.AddFormField('numeric','1');
  22. if min_len>0 then multi.AddFormField('min_len',inttostr(min_len));
  23. if max_len>0 then multi.AddFormField('max_len',inttostr(max_len));
  24. http:=TIdHTTP.Create(nil);
  25. tmpstr:=http.Post('http://anti-captcha.com/in.php',multi);
  26. http.Free;
  27. captcha_id:='';
  28. if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end;
  29. if strpos(Pchar(tmpstr),'OK|')<>nil then captcha_id:=AnsiReplaceStr(tmpstr,'OK|','');
  30. if captcha_id='' then result:='ERROR: bad captcha id';
  31. for i:=0 to 20 do
  32.   begin
  33.   Application.ProcessMessages;
  34.   sleep(5000);
  35.   http:=TIdHttp.Create(nil);
  36.   tmpstr:=http.Get('http://anti-captcha.com/res.php?key='+apikey+'&actio n=get&id='+captcha_id);
  37.   http.Free;
  38.   if strpos(Pchar(tmpstr),'ERROR_')<>nil then begin result:=tmpstr; exit; end;
  39.   if strpos(Pchar(tmpstr),'OK|')<>nil then
  40.     begin
  41.     result:=AnsiReplaceStr(tmpstr,'OK|','');
  42.     exit;
  43.     end;
  44.   Application.ProcessMessages;
  45.   end;
  46. result:='ERROR_TIMEOUT';
  47. end;
  48. procedure TForm1.Button1Click(Sender: TObject);
  49. begin
  50. rsltedit.Text:='recognizing...';
  51. Button1.Enabled:=false;
  52. rsltedit.Text:=recognize(filenameedit.Text,apikeyedit.Text,false,false ,false,0,0);
  53. Button1.Enabled:=true;
  54. end;
  55. end.




Ранг: 101.0 (ветеран), 344thx
Активность: 1.150
Статус: Участник

Создано: 02 апреля 2009 00:56
· Личное сообщение · #2

Тематике форума не соответствует. Обращайтесь на порталы сетевой безопасности.


 eXeL@B —› Программирование —› Проблема с настройкой anti-captcha
Эта тема закрыта. Ответы больше не принимаются.
   Для печати Для печати