I
I
Ilya2018-05-05 22:31:10
PHP
Ilya, 2018-05-05 22:31:10

How to parse a block without a class, ID?

Book in the library's electronic catalog :
5aee044f02d57020636159.png
I need to parse the title proper. How to do it right?
5aee04bfaf207905043054.png
While doing this:

require 'simple_html_dom.php';

// Создаём ДОМ из строки с хтмл-кодом Марк-вью
$html = str_get_html($htmlMarc);

// Прогоняем все <td> на странице, находим нужный
foreach($html->find('td') as $element) {
    if ($a == 1) {
        echo $element->plaintext;
        return;
    }
    if ($element->plaintext == 'Основное заглавие')
        $a = 1;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2018-05-05
@sidorchik

no need for left libraries, no extra searches - use xpath luke)

$doc = new DOMDocument();
@$doc->loadHTMLFile('http://catalog.mgdb.ru:49001/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=31737');

$xpath = new DOMXpath($doc);
echo $xpath->query("//tr[td='Основное заглавие']/td[2]")[0]->nodeValue;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question