PHP code example of sleimanx2 / grawler

1. Go to this page and download the library: Download sleimanx2/grawler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sleimanx2 / grawler example snippets




$client = new Bowtie\Grawler\Client();

$grawler = $client->download('http://example.com');

$grawler->title();

// provide a css path to find the attribute
$grawler->body($path = '.main-content');

// extracts meta keywords (array)
$grawler->keywords();

// extracts meta description 
$grawler->description();

$grawler->images('.content img');

$grawler->videos('iframe');

$grawler->audio('.audio iframe');

// resolve all videos at once 
$videos = $grawler->videos('iframe')->resolve();

foreach($videos as $video)
{
  $video->id; // the video provider id
  $video->title;
  $video->description;
  $video->url;
  $video->embedUrl;
  $video->images; // Collection of Image instances
  $video->author;
  $video->authorId;
  $video->duration;
  $video->provider; //video source
}

$videos = $grawler->videos('iframe')

foreach($videos as $video)
{
  $video->resolve();
  $video->title;
  //...
}

// resolve all audio at once 
$audio = $grawler->audio('.audio iframe')->resolve();

foreach($audio as $track)
{
  $track->id; // the video provider id
  $track->title;
  $track->description;
  $track->url;
  $track->embedUrl;
  $track->images; // Collection of cover photo instances
  $track->author;
  $track->authorId;
  $track->duration;
  $track->provider; //video source
}

$track = $grawler->track('.audio iframe')

foreach($audio as $track)
{
  $track->resolve();
  $track->title;
  //...
}

$links = $grawler->links('.main thumb a')

foreach($links as $link)
{
  print $link
  //or
  print $link->uri
  //or
  print $link->getUri()
}

$client->agent('Googlebot/2.1')->download('http://example.com');

$client->auth('me', '**')

$client->auth('me', '**', $type = 'basic');

$client->method('post');

$config = [
  'youtubeKey'   =>'',
  'soundcloudKey'=>''

  'vimeoKey'    => '',
  'vimeoSecret' => '',

  'soundcloudKey'    => '',
  'soundcloudSecret' => '',
];

$grawler->loadConfig($config);