You are here

function scraping_IMDB in simplehtmldom API 5.2

Same name and namespace in other branches
  1. 6 simplehtmldom/example/scraping/example_scraping_imdb.php \scraping_IMDB()
  2. 7 simplehtmldom/example/scraping/example_scraping_imdb.php \scraping_IMDB()
1 call to scraping_IMDB()
example_scraping_imdb.php in simplehtmldom/example/scraping/example_scraping_imdb.php

File

simplehtmldom/example/scraping/example_scraping_imdb.php, line 4

Code

function scraping_IMDB($url) {

  // create HTML DOM
  $html = file_get_html($url);

  // get title
  $ret['Title'] = $html
    ->find('title', 0)->innertext;

  // get rating
  $ret['Rating'] = $html
    ->find('div[class="general rating"] b', 0)->innertext;

  // get overview
  foreach ($html
    ->find('div[class="info"]') as $div) {

    // skip user comments
    if ($div
      ->find('h5', 0)->innertext == 'User Comments:') {
      return $ret;
    }
    $key = '';
    $val = '';
    foreach ($div
      ->find('*') as $node) {
      if ($node->tag == 'h5') {
        $key = $node->plaintext;
      }
      if ($node->tag == 'a' && $node->plaintext != 'more') {
        $val .= trim(str_replace("\n", '', $node->plaintext));
      }
      if ($node->tag == 'text') {
        $val .= trim(str_replace("\n", '', $node->plaintext));
      }
    }
    $ret[$key] = $val;
  }

  // clean up memory
  $html
    ->clear();
  unset($html);
  return $ret;
}