Created
November 5, 2016 11:47
-
-
Save nishinoshake/16cfe517ad08e7c74a4b54947a59edd4 to your computer and use it in GitHub Desktop.
PHPでスクレイピング
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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