Last active
April 7, 2016 05:36
-
-
Save CLCL/e122f18e50fc1a0cb8e49ef5aa7bfea1 to your computer and use it in GitHub Desktop.
composerでPHP 5.3用のgoutte(ウェブスクレーパー)をインストールする。
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
{ | |
"require": { | |
"php": ">=5.3.3", | |
"fabpot/goutte": "~1.0" | |
} | |
} |
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
curl -sS https://getcomposer.org/installer | php | |
php composer.phar install |
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
<?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