1 Goutte, a simple PHP Web Scraper
2 ================================
4 Goutte is a screen scraping and web crawling library for PHP.
6 Goutte provides a nice API to crawl websites and extract data from the HTML/XML
12 Goutte depends on PHP 5.5+ and Guzzle 6+.
16 If you need support for PHP 5.4 or Guzzle 4-5, use Goutte 2.x (latest `phar
17 <https://github.com/FriendsOfPHP/Goutte/releases/download/v2.0.4/goutte-v2.0.4.phar>`_).
19 If you need support for PHP 5.3 or Guzzle 3, use Goutte 1.x (latest `phar
20 <https://github.com/FriendsOfPHP/Goutte/releases/download/v1.0.7/goutte-v1.0.7.phar>`_).
25 Add ``fabpot/goutte`` as a require dependency in your ``composer.json`` file:
29 composer require fabpot/goutte
34 Create a Goutte Client instance (which extends
35 ``Symfony\Component\BrowserKit\Client``):
41 $client = new Client();
43 Make requests with the ``request()`` method:
47 // Go to the symfony.com website
48 $crawler = $client->request('GET', 'https://www.symfony.com/blog/');
50 The method returns a ``Crawler`` object
51 (``Symfony\Component\DomCrawler\Crawler``).
53 To use your own Guzzle settings, you may create and pass a new Guzzle 6
54 instance to Goutte. For example, to add a 60 second request timeout:
59 use GuzzleHttp\Client as GuzzleClient;
61 $goutteClient = new Client();
62 $guzzleClient = new GuzzleClient(array(
65 $goutteClient->setClient($guzzleClient);
71 // Click on the "Security Advisories" link
72 $link = $crawler->selectLink('Security Advisories')->link();
73 $crawler = $client->click($link);
79 // Get the latest post in this category and display the titles
80 $crawler->filter('h2 > a')->each(function ($node) {
81 print $node->text()."\n";
88 $crawler = $client->request('GET', 'https://github.com/');
89 $crawler = $client->click($crawler->selectLink('Sign in')->link());
90 $form = $crawler->selectButton('Sign in')->form();
91 $crawler = $client->submit($form, array('login' => 'fabpot', 'password' => 'xxxxxx'));
92 $crawler->filter('.flash-error')->each(function ($node) {
93 print $node->text()."\n";
99 Read the documentation of the `BrowserKit`_ and `DomCrawler`_ Symfony
100 Components for more information about what you can do with Goutte.
105 Goutte is pronounced ``goot`` i.e. it rhymes with ``boot`` and not ``out``.
107 Technical Information
108 ---------------------
110 Goutte is a thin wrapper around the following fine PHP libraries:
112 * Symfony Components: `BrowserKit`_, `CssSelector`_ and `DomCrawler`_;
114 * `Guzzle`_ HTTP Component.
119 Goutte is licensed under the MIT license.
121 .. _`Composer`: https://getcomposer.org
122 .. _`Guzzle`: http://docs.guzzlephp.org
123 .. _`BrowserKit`: https://symfony.com/components/BrowserKit
124 .. _`DomCrawler`: https://symfony.com/doc/current/components/dom_crawler.html
125 .. _`CssSelector`: https://symfony.com/doc/current/components/css_selector.html