Via Composer
$ composer require sleimanx2/grawlerrequire_once('vendor/autoload.php');
$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');In order resolve media attributes you need to load providers's configuration
Current video resolvers (youtube , vimeo)
// resolve all videos at once
$videos = $grawler->videos('iframe')->resolve();then you can access videos attributes as follow
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
}you can also resolve videos individually as follow
$videos = $grawler->videos('iframe')
foreach($videos as $video)
{
$video->resolve();
$video->title;
//...
}Current video resolvers (soundcloud)
// resolve all audio at once
$audio = $grawler->audio('.audio iframe')->resolve();then you can access videos attributes as follow
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
}you can also resolve audio individually as follow
$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');Recomended : http://webmasters.stackexchange.com/questions/6205/what-user-agent-should-i-set
$client->auth('me', '**')you can change the auth type as follow
$client->auth('me', '**', $type = 'basic');$client->method('post');By default the grawler tries to access those environment variables
GRAWLER_YOUTUBE_KEY
GRAWLER_VIMEO_KEY
GRAWLER_VIMEO_SECRET
GRAWLER_SOUNDCLOUD_KEY
GRAWLER_SOUNDCLOUD_SECRET
if you don't use env vars you can load configuration as follow.
$config = [
'youtubeKey' =>'',
'soundcloudKey'=>''
'vimeoKey' => '',
'vimeoSecret' => '',
'soundcloudKey' => '',
'soundcloudSecret' => '',
];
$grawler->loadConfig($config);$ phpunit --testsuite unit$ phpunit --testsuite integrationNB: you should set your ptoviders key (youtube,vimeo,soundcloud...) to run integration tests
Please see CONTRIBUTING
If you discover any security related issues, please email sleiman@bowtie.land instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.