linkthrow/goutte

Laravel 5 package for Gouette, a simple PHP Web Scraper
16 1
Install
composer require linkthrow/goutte
PHP:>=5.4.0
License:MIT
Last Updated:Jul 29, 2016
Links: GitHub  ·  Packagist
Maintainer: linkthrow

Laravel 5 Facade for Goutte

This repository implements a simple ServiceProvider that makes a singleton instance of the Goutte client easily accessible via a Facade in Laravel 5. See @FriendsOfPHP/Goutte for more information about the php web scraper and its interfaces.

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 weidner/goutte:@dev

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": "weidner/laravel-goutte-test",
  "description": "A dummy project used to test the Laravel Goutte Facade.",

  // ...

  "require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.2.*",
    "weidner/goutte": "@dev",
    // ...
  },

  //...
}

Usage

In ordet 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' => [

    // ...

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,
    Weidner\Goutte\GoutteServiceProvider::class, // [1]

  ],

  // ...

  'aliases' => [

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

    // ...

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

];

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

// app/Http/routes.php

Route::get('/', function() {
  $crawler = Goutte::request('GET', 'http://duckduckgo.com/?q=Laravel');
  $url = $crawler->filter('.result__title > a')->first()->attr('href');
  dump($url);
  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.

Related Packages

reliese/laravel

Reliese Components for Laravel Framework code generation.

3,991,690 1,705
php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the...

53,315 160
laravel-ja/laravel

The Laravel Framework.

5,667 17
kavenegar/laravel

laravel 4 and 5 kavenegar integration

368,693 86
laravel/laravel

The skeleton application for the Laravel framework.

64,930,508 84,972