Очистите, используя simple_html_dom. php - PullRequest
1 голос
/ 29 апреля 2020

Я пытаюсь очистить поля контактов и адресов с веб-сайта: https://www.houzz.com/professionals/handyman/c/US

html выглядит следующим образом (до нажатия кнопки «Нажмите, чтобы позвонить»):

<span class="hz-pro-search-result__contact-info">
   <span class="icon-font icon-phone hz-pro-search-result__contact-info__icon" aria-hidden="true"></span> 
      <span class="hz-pro-search-result__contact-info__cover">Click to call</span>
 </span>

html выглядит следующим образом (после нажатия «Нажмите, чтобы позвонить»):

<span class="hz-pro-search-result__contact-info">
  <span class="icon-font icon-phone hz-pro-search-result__contact-info__icon" aria-hidden="true"> 
</span>(954) 399-0454</span>

Моя проблема в том, что я не могу очистить контактный номер. вместо этого он очищает 'Click to call' Вот мой код: function scrape () {require_once APPPATH .'third_party / simple_html_dom. php ';

    // Create DOM from URL or file
    $html = file_get_html('https://www.houzz.com/professionals/handyman/c/US');

    // creating an array of elements
    $videos = [];

    // Find top ten videos
    $i = 1;
    foreach ($html->find('li.hz-pro-search-results__item') as $video) {
            if ($i > 10) {
                    break;
            }

            // Find item link element
            $videoDetails1 = $video->find('span.hz-pro-search-result__contact-info', 0);
            $videoDetails = $video->find('span.hz-pro-search-result__location-info__text', 0);

            // get title attribute
            $videoTitle1 = $videoDetails1->plaintext;
            $videoTitle = $videoDetails->plaintext;

            // get href attribute
            //$videoUrl = 'https://linkedin.com' . $videoDetails->href;

            // push to a list of videos
            $videos[] = [
                    'title1' => $videoTitle1,
                    'title' => $videoTitle,
                    //'url' => $videoUrl
            ];

            $i++;
    }

    var_dump($videos);
}
...