I am writing a parser for one site. I use biblioteka

simple_html_dom

I wrote this code:

<?php require "simple_html_dom.php"; /* Получаем документ, находим необходимые элелементы для авторизации и устанавливаем им значения логина и пароля. */ $html = file_get_html('http://sb.ua/?id=2&cat=1'); foreach($html->find('input[name=login]') as $login) $login->value = 'k@l.ru'; foreach($html->find('input[name=pass]') as $login) $login->value = '15r'; // проверяем установлено ли значение foreach($html->find('input[name=login]') as $element) echo $element->value . '<br>'; foreach($html->find('input[name=pass]') as $element) echo $element->value . '<br>'; ?> 

You need a form, the elements of which are set values ​​for authorization, send for processing on their server. After, you need to get the returned document for further parsing.

P.S. link to the page with the library here.

If there are options for implementing this in JavaScript, I will be happy to take a look.

    1 answer 1

    I have not seen such a complicated authorization method yet. Although seen like. Materiel would teach something ...
    Authorization is built by transmitting a POST request, which is, in general, a string (HTTP1), the browser needs DOM for visualization and logical separation of elements, this is not necessary for the server, such libraries are used to parse values ​​from existing HTML documents.

    Given this, you can simply do this:

     $context = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded' . PHP_EOL, 'content' => 'login={Your login}&pass={Your password}&remember=0', // Хм, фигурные скобки нужно убрать, тут они для наглядности, а то вдруг... ], ]); file_get_contents('http://sborka.ua/inc/login.php', false, $context) 
    • Understood in your code, studied the functions used in it, thanks. But authorization does not pass. Returns homepage content ... - Denis Oleshchenko
    • @DenisOleshchenko, here you have to dig in place already - maybe you need a special title, maybe something else. - user207618