Answer the question
In order to leave comments, you need to log in
Captcha entry via curl. How to send a captcha?
Hello! I am engaged in layout in a seo-company, I am a little familiar with php, they asked me to auto-register Yandex accounts for parsing results through the Key Collector. I drew 2 functions, one takes data from https://passport.yandex.ru/registration, including captcha. Another one processes this captcha through api ruCaptcha and returns the answer. But it turns out that when I try to enter data on the Yandex page via curl, the captcha has already changed.
function regYandexAcc($login, $pass)
{
$url = 'https://passport.yandex.ru/registration';
$cookiefile = 'cookie.txt';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url ); // отправляем на
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0");
curl_setopt($ch, CURLOPT_HEADER, 0); // пустые заголовки
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвратить то что вернул сервер
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // следовать за редиректами
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);// таймаут
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIESESSION, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); // сохранять куки в файл
curl_setopt($ch, CURLOPT_POST, true);
$str = curl_exec($ch);
$dom = new DOMDocument();
$dom->loadHTML($str);
$imgfind = $dom->getElementsByTagName('img');
$inputFind = $dom->getElementsByTagName('input');
foreach ($inputFind as $key) {
$secret[] = $key->getAttribute('value');
}
foreach($imgfind as $im) {
$test = parse_url($im->getAttribute('src'));
if($test['host'] == 'ext.captcha.yandex.net'){
file_put_contents('captcha.png', file_get_contents($im->getAttribute('src')));
$secret[1] = reCaptcha(); //получаем каптчу через сервис ruCaptha
}
}
$postLoginFields = array();
$postLoginFields['track_id'] = $secret[0];
$postLoginFields['language'] = 'ru';
$postLoginFields['firstname'] = $login;
$postLoginFields['lastname'] = $login;
$postLoginFields['login'] = $login;
$postLoginFields['password'] = $pass;
$postLoginFields['password_confirm'] = $pass;
$postLoginFields['human-confirmation'] = 'captcha';
$postLoginFields['hint_question_id'] = 15;
$postLoginFields['hint_answer'] = $login;
$postLoginFields['key'] = $secret[20];
$postLoginFields['captcha_mode'] = 'text';
$postLoginFields['answer'] = $secret[1];
$postLoginFields['eula_accepted'] = true;
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postLoginFields));
$output = curl_exec($ch);
echo $output;
echo '<pre>';
var_dump($postLoginFields);
echo '</pre>';
// return $output;
}
regYandexAcc('Aleks123qwerty122', "asdasfasfasfaa3312");
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question