PHPackages                             gueroverde/goutte - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gueroverde/goutte

ActiveLibrary

gueroverde/goutte
=================

Laravel 5 package for Goutte, a simple PHP Web Scraper

1.3.0(6y ago)120MITPHPPHP &gt;=5.4.0

Since Jan 22Pushed 6y agoCompare

[ Source](https://github.com/gueroverde/laravel-goutte)[ Packagist](https://packagist.org/packages/gueroverde/goutte)[ Docs](https://github.com/dweidner/laravel-goutte)[ RSS](/packages/gueroverde-goutte/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (7)Used By (0)

Laravel 6 Facade for Goutte
===========================

[](#laravel-6-facade-for-goutte)

This repository implements a simple [ServiceProvider](https://laravel.com/docs/master/providers) that makes a singleton instance of the Goutte client easily accessible via a [Facade](https://laravel.com/docs/master/facades) in [Laravel 5](http://laravel.com). See [@FriendsOfPHP/Goutte](https://github.com/FriendsOfPHP/Goutte) for more information about the PHP web scraper and its interfaces.

Installation using [Composer](https://getcomposer.org/)
-------------------------------------------------------

[](#installation-using-composer)

In your terminal application move to the root directory of your laravel project using the `cd` command and require the project as a dependency using composer.

```
$ cd ~/Sites/laravel-example-project
$ composer require gueroverde/goutte
```

This will add the following lines to your `composer.json` and download the project and its dependencies to your projects `./vendor` directory:

```
// ./composer.json
{
    "name": "gueroverde/laravel-goutte-test",
    "description": "A dummy project used to test the Laravel Goutte Facade.",

    // ...

    "require": {
        "php": ">=5.5.9",
        "laravel/framework": "^6.0",
        "gueroverde/goutte": "1.3.*",
        // ...
    },

    //...
}
```

Usage
-----

[](#usage)

In order to use the static interface we first have to customize the application configuration to tell the system where it can find the new service. Open the file `config/app.php` in the editor of your choice and add the following lines (`[1]`, `[2]`):

```
// config/app.php

return [

    // ...

    'providers' => [

        // ...

        /*
         * Package Service Providers...
         */
        Weidner\Goutte\GoutteServiceProvider::class, // [1]

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

    ],

    // ...

    'aliases' => [

        'App' => Illuminate\Support\Facades\App::class,
        'Artisan' => Illuminate\Support\Facades\Artisan::class,

        // ...

        'Goutte' => Weidner\Goutte\GoutteFacade::class, // [2]
        'Hash' => Illuminate\Support\Facades\Hash::class,

        // ...
    ],

];
```

Now you should be able to use the facade within your application. Laravel will autoload the corresponding classes once you use the registered alias.

```
// routes/web.php

Route::get('/', function() {
    $crawler = Goutte::request('GET', 'https://duckduckgo.com/html/?q=Laravel');
    $crawler->filter('.result__title .result__a')->each(function ($node) {
      dump($node->text());
    });
    return view('welcome');
});
```

*TIP:* If you retrieve a "Class 'Goutte' not found"-Exception try to update the autoloader by running `composer dump-autoload` in your project root.

Configuration
-------------

[](#configuration)

You can customize the default request options to apply to each request of the client. Copy the default configuration to your application directory first:

```
php artisan vendor:publish --provider="Weidner\Goutte\GoutteServiceProvider"
```

Open the created file in the `config/goutte.php` and customize the configuration options to your liking.

```
