lang/php

Simple PHP Web Scraper Guotte

C/H 2018. 6. 29. 08:30

Goutte, a simple PHP Web Scraper

구트(Goutte), 심플 PHP 웹 스크레이퍼

Installation

composer require fabpot/goutte

Usage

require_once "vendor/autoload.php";

use Goutte\Client;

$client = new Client();
$crawler = $client->request('get', "http://www.symfony.com/blog/");

$crawler->filter('title')->each(function($node){
    echo $node->text()."\n";
});

Results

The Symfony Blog

Usage2

require_once "vendor/autoload.php";

use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;

$client = new Client();
$guzzle = new GuzzleClient([
    'timeout' => 60,    // 60초 요청제한
]);
$client->setClient($guzzle);

$crawler = $client->request('GET', 'https://www.symfony.com/blog/');
$crawler->filter('title')->each(function($node){
    echo $node->text()."\n";
});

// Click on the "Security Advisories" link, 클릭
$link = $crawler->selectLink('Security Advisories')->link();
$crawler = $client->click($link);

$crawler->filter('title')->each(function($node){
    echo $node->text()."\n";
});

Results

The Symfony Blog
Security Advisories posts on the Symfony blog


반응형

'lang > php' 카테고리의 다른 글

PHP Goutte Cookie  (0) 2018.07.01
PHP Guzzle Scraper  (0) 2018.06.30
PHP Laravel Framework helloWorld  (0) 2018.06.15
PHP reactPHP helloWorld  (0) 2018.06.14
PHP workman Container helloWorld  (0) 2018.06.12