[PHP] Проблема с отсылкой капчи в Google

12 3
A0
На сайте с 15.10.2012
Offline
2
6874

Всем доброго времени суток!

Столкнулся с проблемой - не могу побороть каптчу Google. Что делаю:

1) парсю капчу Google, затем отправляю ее на Antigate

2) получают тестовое представление капчи и отправляю ее на google.com/sorry/Captcha

Но в ответ получаю снова страницу с капчей. Ниже приведу код, надеюсь кто-то сможет указать на ошибку.


$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'http://google.com/sorry/');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl,CURLOPT_TIMEOUT,10);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
curl_setopt($curl, CURLOPT_REFERER, 'http://www.google.com/');
curl_setopt($curl,CURLOPT_ENCODING,"gzip,deflate");
$response = curl_exec($curl);
//parsing cookies
$cookieStart = strpos($response, 'Set-Cookie:');
$cookieString = substr($response, $cookieStart+12, strpos($response, "\n", $cookieStart) - ($cookieStart+12) -1);
//detecting captcha image path
$begin = strpos($response, '<img src="/sorry/image')+10;
$img_path = substr($response, $begin, strpos($response, '"', $begin) - $begin);
$captcha_id = substr($img_path, 16, strpos($img_path, '&') - 16);
$img_path = 'http://google.com'.$img_path;
//saving captcha image
file_put_contents('/tmp/'.$captcha_id.'.jpg', file_get_contents($img_path));
//sending captcha to Antigate
$text = Antigate::recognize(....);
//building url for submitting captcha
curl_setopt($curl,CURLOPT_URL,'http://www.google.com/sorry/Captcha?id='.$captcha_id.'&captcha='.$text.'&submit=Submit');
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_HEADER,false);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION, true);
$http_headers = array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: en-US,en;q=0.8',
'Connection: keep-alive',
'Cookie: '.$cookieString,
'Host: google.com',
'Referer: http://google.com/sorry/',
'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $http_headers);
$response = curl_exec($curl);
echo $response;

И к великому сожалению в $response опять приходит страница с капчей :gm:

platitude
На сайте с 16.10.2012
Offline
3
#1

curl_setopt($curl,CURLOPT_HEADER,false);

должно быть

curl_setopt($curl,CURLOPT_HEADER,1);

иначе заголовки с куками не будут переданы в $response

Парсер на заказ, индивидуальный подход к разработке. Качественно, удобно и просто. Связь через личные сообщения.
A0
На сайте с 15.10.2012
Offline
2
#2
platitude:
curl_setopt($curl,CURLOPT_HEADER,false);
должно быть
curl_setopt($curl,CURLOPT_HEADER,1);
иначе заголовки с куками не будут переданы в $response

Изменил, но результат тот же.

platitude
На сайте с 16.10.2012
Offline
3
#3
avad0n:
Изменил, но результат тот же.

Покажите вывод содержимого переменной $response с включёнными заголовками в cURL, пожалуйста

A0
На сайте с 15.10.2012
Offline
2
#4
platitude:
Покажите вывод содержимого переменной $response с включёнными заголовками в cURL, пожалуйста

HTTP/1.1 503 Service Unavailable

Date: Tue, 16 Oct 2012 18:44:03 GMT

Pragma: no-cache

Expires: Fri, 01 Jan 1990 00:00:00 GMT

Cache-Control: no-cache, must-revalidate

Content-Type: text/html

Server: HTTP server (unknown)

Content-Length: 2563

X-XSS-Protection: 1; mode=block

X-Frame-Options: SAMEORIGIN

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>http://www.google.com/</title></head>

<body style="font-family: arial, sans-serif; background-color: £fff; color: £000; padding:20px; font-size:18px;" onload="e=document.getElementById('captcha');if(e)`e.focus();ñ">

<div style="max-width:400px;">

<hr noshade size="1" style="color:£ccc; background-color:£ccc;"><br>

To continue, please type the characters below:<br><br>

<img src="/sorry/image?id=10677437520191455856&amp;hl=en" border="1" alt="Please enable images"><br><br><form action="Captcha" method="get"><input type="hidden" name="continue" value="http://www.google.com/"><input type="hidden" name="id" value="10677437520191455856"><input type="text" name="captcha" value="" id="captcha" size="12" style="font-size:16px; padding:3px 0 3px 5px; margin-left:0px;"><input type="submit" name="submit" value="Submit" style="font-size:18px; padding:4px 0;"><br><br><br></form>

<hr noshade size="1" style="color:£ccc; background-color:£ccc;">

<div style="font-size:13px;">

<b>About this page</b><br><br>Our systems have detected unusual traffic from your computer network. This page checks to see if it&£39;s really you sending the requests, and not a robot. <a href="£" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br>

<div id="infoDiv" style="display:none; background-color:£eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;">

This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="http://www.google.com/accounts/TOS">Terms of Service</a>. The block will expire shortly after those requests stop. In the meantime, solving the above CAPTCHA will let you continue to use our services.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests. If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible. <a href="http://www.google.com/support/bin/answer.py?answer=86640">Learn more</a><br><br>Sometimes you may be asked to solve the CAPTCHA if you are using advanced terms that robots are known to use, or sending requests very quickly.

</div>

IP address: 94.243.223.233<br>Time: 2012-10-16T18:44:03Z<br>URL: http://www.google.com/<br>

</div>

</div>

</body>

</html>

IL
На сайте с 20.04.2007
Offline
435
#5

Не увидел обработку

<input type="hidden" name="continue"
... :) Облачные серверы от RegRu - промокод 3F85-3D10-806D-7224 ( http://levik.info/regru )
A0
На сайте с 15.10.2012
Offline
2
#6
ivan-lev:
Не увидел обработку

Поменял на


curl_setopt($curl,CURLOPT_URL,'http://www.google.com/sorry/Captcha?continue='.urlencode('http://www.google.com/').'&id='.$captcha_id.'&captcha='.$text.'&submit=Submit');

Но тоже самое, http 503 и страница с капчей.

LEOnidUKG
На сайте с 25.11.2006
Offline
1776
#7

А зачем кукки хранить в файле, а потом их вырезать и подсовывать в заголовок?

✅ Мой Телеграм канал по SEO, оптимизации сайтов и серверов: https://t.me/leonidukgLIVE ✅ Качественное и рабочее размещение SEO статей СНГ и Бурж: https://getmanylinks.ru/ ✅ Настройка и оптимизация серверов https://getmanyspeed.ru/
A0
На сайте с 15.10.2012
Offline
2
#8
LEOnidUKG:
А зачем кукки хранить в файле, а потом их вырезать и подсовывать в заголовок?

По сути это старый кусок кода. Убрал чтобы не смущать народ ))

LEOnidUKG
На сайте с 25.11.2006
Offline
1776
#9

А данные гуглу точно нужны в GET?

A0
На сайте с 15.10.2012
Offline
2
#10
LEOnidUKG:
А данные гуглу точно нужны в GET?

Ну там же указано в теге формы method="get". Да и через developer tools в браузере проверил, там действительно get-запрос.

12 3

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий