I
I
Ilya2018-05-10 13:26:40
PHP
Ilya, 2018-05-10 13:26:40

Why is the XPath query not working correctly?

I parsed the search results for the library directory . Now we need to extract the necessary data from it. To begin with, at least find the number of divs with the searchrez class in the div with the searchrezult ID :
5af41da0d95c3224033486.png
In the source, the structure is the same as in the console:
5af41f44eef93695910754.png
But instead of 4, 0 is displayed:

echo $xpathSKBM->query('//div[@id="searchrezult"]/div[@class="searchrez"]')->length;

Help me please.
Whole code:
$bookTitle = 'Код Дурова';

require '../vendor/autoload.php';

use GuzzleHttp\Client;

// Инициализируем класс для работы с удалёнными веб-ресурсами
$client = new Client();

// Делаем запрос на страницу выдачи, получаем ответ
$response = $client->request('POST', 'http://skbm.nekrasovka.ru/request', [
    'form_params' => [
        '_service' =>'STORAGE:opacfindd:IndexView',
        '_action' => 'php',
        '_errorhtml' => 'error1',
        '_handler' => 'search/search.php',
        'querylist' => '<_service>STORAGE:opacfindd:FindView[separator]<_version>2.5.0[separator]<session>26026[separator]<_start>0[separator]<start>0[separator]<$length>15[separator]<length>15[separator]<iddb>1[separator]<_showstr><i>Заглавие</i> '.$bookTitle.'[separator]<_str>[bracket]TITL '.$bookTitle.'[/bracket][separator]<$outform>SHORTFM[separator]<outformList[0]/outform>SHORTFM[separator]<outformList[1]/outform>LINEORD[separator]<outformList[2]/outform>SHORTFMS[separator]<outformList[3]/outform>SHORTFMSTR[separator]<$filterstr>[bracket][bracket]LRES [apos]ТЕКСТЫ[apos][/bracket][/bracket] AND [bracket]LPUB [apos]КНИГИ[apos][/bracket][separator]<$filtersids>filter_1_2_0[END]filter_1_3_0[separator]<$fshowstr><i>вид документа</i> тексты И <i>вид издания</i> книги[separator]<query/body>(TITL '.$bookTitle.') AND ((LRES \'ТЕКСТЫ\')) AND (LPUB \'КНИГИ\')[separator]<_history>yes[separator]<userId>ADMIN[separator]<$linkstring>043[ID]Заказ документа[END]044[ID]Заказ копии документа[END][separator]<level[0]>Full[separator]<level[1]>Retro[separator]<level[2]>Unfinished[separator]<level[3]>Identify[separator]<$swfterm>[bracket]TITL '.$bookTitle.'[/bracket] AND [bracket][bracket]LRES [apos]ТЕКСТЫ[apos][/bracket][/bracket] AND [bracket]LPUB [apos]КНИГИ[apos][/bracket][separator]<_iddb>1[separator]<$addfilters>[NEXT]filter_1_1_else[IND]fixed_1_0_1525854941893[CLASS](LFR \'печатная/рукописная\')[TEXT]печатная/рукописная[separator]<$typework>search[separator]<$basequant>2391872[separator]<$flag45>yes',
        '_numsean' => '26026'
    ]
]);

// Выводим нужное из хтмла выдачи
$htmlSKBM = $response->getBody();
$docSKBM = new DOMDocument();
@$docSKBM->loadHTMLFile($htmlSKBM);

$xpathSKBM = new DOMXpath($docSKBM);
echo $xpathSKBM->query('//div[@id="searchrezult"]/div[@class="searchrez"]')->length;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question