PHP Classes

File: example/example_scraping_imdb.php

Recommend this page to a friend!
  Packages of Lars Moelleken   Simple HTML DOM   example/example_scraping_imdb.php   Download  
File: example/example_scraping_imdb.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple HTML DOM
Manipulate HTML elements using DOMDocument
Author: By
Last change: Update of example/example_scraping_imdb.php
Date: 4 years ago
Size: 625 bytes
 

Contents

Class file image Download
<?php

require_once '../vendor/autoload.php';

function scraping_imdb($url)
{
    // init
    $return = [];

    // create HTML DOM
    $dom = \voku\helper\HtmlDomParser::file_get_html($url);

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

    // get rating
    $return['Rating'] = $dom->find('.ratingValue strong', 0)->getAttribute('title');

    return $return;
}

// -----------------------------------------------------------------------------

$data = scraping_imdb('http://imdb.com/title/tt0335266/');

foreach ($data as $k => $v) {
    echo '<strong>' . $k . ' </strong>' . $v . '<br>';
}