Skip to content

Instantly share code, notes, and snippets.

@nishinoshake
Created November 5, 2016 11:47
Show Gist options
  • Save nishinoshake/16cfe517ad08e7c74a4b54947a59edd4 to your computer and use it in GitHub Desktop.
Save nishinoshake/16cfe517ad08e7c74a4b54947a59edd4 to your computer and use it in GitHub Desktop.
PHPでスクレイピング
// Goutte is good
//
// https://github.com/FriendsOfPHP/Goutte
//
// * install *
// composer require fabpot/goutte
use Goutte\Client;
$client = new Client();
$crawler = $client->request('GET', 'http://www.symfony.com/blog/');
// selector like jquery
$crawler->filter('h2 > a')->each(function ($node) {
print $node->text()."\n";
});
// detail here
// http://symfony.com/doc/current/components/dom_crawler.html
$crawler->filter('h2 > a')->text();
$crawler->filter('h2 > a')->attr('href');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment