Skip to content

Instantly share code, notes, and snippets.

@CLCL
Last active April 7, 2016 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CLCL/e122f18e50fc1a0cb8e49ef5aa7bfea1 to your computer and use it in GitHub Desktop.
Save CLCL/e122f18e50fc1a0cb8e49ef5aa7bfea1 to your computer and use it in GitHub Desktop.
composerでPHP 5.3用のgoutte(ウェブスクレーパー)をインストールする。
{
"require": {
"php": ">=5.3.3",
"fabpot/goutte": "~1.0"
}
}
curl -sS https://getcomposer.org/installer | php
php composer.phar install
<?php
require_once __DIR__ . '/vendor/autoload.php';
ini_set('default_charset', 'UTF-8');
define(USER_AGENT, 'Goutte/1.0.7');
$client = new Goutte\Client;
$client->setHeader('User-Agent', USER_AGENT);
$crawler = $client->request('GET', 'http://example.com/');
$crawler->filter('h1')->each(function($node) {
echo $node->text()."\n";
});
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment