I want to get the results from the form on the page https://rosreestr.ru/wps/portal/p/cc_ib_portal_services/online_request/
There is a captcha. Got it. I also got the code from the url which is generated. Made a cookie record. I receive a captcha parser, I enter it - but in the end it answers that the captcha is not varn.
At the same time, if I switch the browser to the page, then I will see the same numbers on the captcha as it gives me in the parser, and when I enter it in the browser, everything is fine. Something is missing apparently from me, I can not understand what.
I provide my code that can be reproduced, only you will need to connect the HTML library DOM PARSER:
session_start(); require_once __DIR__ . '/simple_html_dom_parser.php'; if (!$_GET) { $url = 'https://rosreestr.ru/wps/portal/p/cc_ib_portal_services/online_request/'; $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, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвратить то что вернул сервер curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); // следовать за редиректами curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);// таймаут4 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// просто отключаем проверку сертификата curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/my_cookies.txt'); // сохранять куки в файл curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/my_cookies.txt'); $content = curl_exec($ch); preg_match_all('/^Content-Location:(.*)$/mi', $content, $matches); if (!empty($matches[1])) { $realUrl = trim($matches[1][0]); }else{ exit('No real url'); } $findCaptcha = str_get_html($content); $img = $findCaptcha->find('tr td #captchaImage2'); $urlCaptcha = $img[0]->src; $key = str_replace(array('p0/', '=NJcaptcha=/'), '', $urlCaptcha); $goToCaptcha = 'https://rosreestr.ru'.$realUrl.$urlCaptcha; $dopUrlForm = '=MEcontroller!QCPSearchAction==/'; $formToUrl = explode('/', $realUrl); array_splice($formToUrl, 10); $goFormTo = 'https://rosreestr.ru'.implode('/', $formToUrl).'/p0/'.$key.$dopUrlForm; echo "<img src='".$goToCaptcha."'>"; echo "<form method='get'><input type='text' name='captcha'><input type='submit' value='go'></form>"; $_SESSION['referer'] = 'https://rosreestr.ru'.$realUrl; $_SESSION['form'] = $goFormTo; }else{ $post = 'search_action=true&subject=®ion=&settlement=&cad_num=&start_position=59&obj_num=&old_number=&search_type=ADDRESS&subject_id=120000000000®ion_id=120401000000&street_type=str0&street=&house=54%2F5&building=&structure=&apartment=&right_reg=&encumbrance_reg=&captchaText='.$_GET['captcha']; $ch1 = curl_init(); curl_setopt($ch1, CURLOPT_URL, $_SESSION['form']); curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/my_cookies.txt'); // сохранять куки в файл curl_setopt($ch1, CURLOPT_COOKIEFILE, dirname(__FILE__).'/my_cookies.txt'); curl_setopt($ch1, CURLOPT_POST, 1); curl_setopt($ch1, CURLOPT_POSTFIELDS, $post); curl_setopt($ch1, CURLOPT_REFERER, $_SESSION['referer']); curl_setopt($ch1, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"); curl_setopt($ch1, CURLOPT_HEADER, array('Host: rosreestr.ru', 'Origin: https://rosreestr.ru', 'Upgrade-Insecure-Requests: 1')); curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec($ch1); echo $data; }
I would be grateful for the help!