2017 © Pedro Peláez
 

library fluent-web-crawler

A web crawler with a fluent interface

image

rebelinblue/fluent-web-crawler

A web crawler with a fluent interface

  • Friday, April 28, 2017
  • by REBELinBLUE
  • Repository
  • 1 Watchers
  • 4 Stars
  • 724 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 13 % Grown

The README.md

logo, (*1)

Fluent Web Crawler

StyleCI Build Status Code Climate Code Coverage, (*2)

A web scraping library for PHP with a nice fluent interface., (*3)

A fork of laravel/browser-kit-testing, repurposed to use with real HTTP requests., (*4)

Developed for a project I worked on at Sainsbury's., (*5)

Requirements

PHP 7.1+ and Goutte 3.1+, (*6)

Installation

The recommended way to install the library is through Composer., (*7)

Add rebelinblue/fluent-web-crawler as a require dependency in your composer.json file:, (*8)

composer require rebelinblue/fluent-web-crawler

Usage

Create an instance of the Crawler, (*9)

use REBELinBLUE\Crawler;

$crawler = new Crawler();

Visit a URL, (*10)

$crawler->visit('http://www.example.com');

Interact with the page, (*11)

$crawler->type('username', 'admin')
        ->type('password', 'password')
        ->press('Login');

// This can also be written as the following

$crawler->submitForm('Login', [
    'username' => 'admin',
    'password' => 'password',
]);

Check the response is as expected, (*12)

if ($crawler->dontSeeText('Hello World')) {
    throw new \Exception('The page does not contain the expected text');
}

For a full list of the available actions see api.md., (*13)

Customising the HTTP client settings

If you wish to customize the instance of Goutte which is used (or more likely, the instance of Guzzle), you can inject your own instance when constructing the class. For example, you may want to increase Guzzle's timeout, (*14)

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

$goutteClient = new GoutteClient();
$guzzleClient = new GuzzleClient([
    'timeout' => 60,
]);
$goutteClient->setClient($guzzleClient);

$crawler = new Crawler($goutteClient);

Further Reading

Fluent Crawler is a wrapper around the following PHP libraries., (*15)

The Versions