PHP Classes

File: examples/scraping_imdb.php

Recommend this page to a friend!
  Classes of Lars Moelleken   PHP httpful Request   examples/scraping_imdb.php   Download  
File: examples/scraping_imdb.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP httpful Request
Send and process HTTP requests using handler class
Author: By
Last change:
Date: 3 years ago
Size: 818 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

require
__DIR__ . '/../vendor/autoload.php';

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

   
// create HTML DOM
   
$response = \Httpful\Client::get_request($url)
        ->
expectsHtml()
        ->
disableStrictSSL()
        ->
send();

   
/** @var \voku\helper\HtmlDomParser $dom */
   
$dom = $response->getRawBody();

   
// 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>';
}