K
K
keatra2017-06-05 04:12:59
PHP
keatra, 2017-06-05 04:12:59

How to extract the necessary information?

Hello. I started parsing a certain site and ran into a problem, I collected all the information, only the address was left to get, but it didn’t work out. Tell me how you can use the phpqyery library to extract the address from the code below.
Thanks in advance.

<td class="ccol" valign=top colspan=2>
  <div class='cd'>Тип: <a href='сылка'>Клиники</a></div> 
     Город: Киев
       <br>
       Район: <a href="сылка" title="Поиск по району">Лукьяновка - Сырец</a>
       <br>
          Адрес: ул. Багговутовская, 1, корп. Р-2
         <br> 
    	 <br>
<div id="catalog_rating" class="stat">
    <div class="title">Рейтинг заведения:</div>
    .....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2017-06-05
@keatra

It's better to use a regular expression.

preg_match("|Адрес: (.*)<br>|", $str, $out);
var_dump($out[1]);

Or after phpquery additionally process the result:
$elem = $pq->find('.ccol');
$text = $elem->html();
list(,,,,$adr,) = explode("\r\n", $text); // берём пятую строку из элемента .ccol
$adr = trim(strip_tags($adr)); // убираем из неё лишний html и пробелы

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question