A
A
artem782017-07-06 19:30:59
PHP
artem78, 2017-07-06 19:30:59

How to extract text via xpath?

There is this list:

<ol class="breadcrumb">
    <li><a href="/">Главная</a></li>
    <li><a href="/catalog/">Каталог</a></li>
    <li><a href="/catalog/vstraivaemye-svetilniki/">Встраиваемые светильники</a></li>
    <li class="active">Встраиваемый светильник Arte Lamp Cardani A5941PL-1SI</li>
</ol>

You need to get the name of all items:
Главная
Каталог
Встраиваемые светильники
Встраиваемый светильник Arte Lamp Cardani A5941PL-1SI

This xpath query //ol[@class="breadcrumb"]/li/text()returns only the text of elements without a link. How can this be done for all elements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
artem78, 2017-07-06
@artem78

Found a solution:

$res = $xpath->query('//ol[@class="breadcrumb"]/li');
  foreach ($res as $item) {
    echo $item->textContent . "\n";
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question