Skip to content

phpscrapervsgoutte

GPL-3.0-or-later 27 2 588
238 (month) May 04 2020 3.0.0(2024-04-09 15:34:59 ago)
9,164 2 137 MIT
Dec 02 2012 8.5 thousand (month) v4.0.3(2023-04-01 09:05:33 ago)

PHPScraper is a universal web-util for PHP. The main goal is to get stuff done instead of getting distracted with selectors, preparing & converting data structures, etc. Instead, you can just go to a website and get the relevant information for your project.

PHPScraper is a minimalistic scraper framework that is built on top of other popular scraping tools.

Features:

  • Direct access to page basic features like: Meta data, Links, Images, Headings, Content, Keywords etc.
  • File downloading.
  • RSS, Sitemap and other feed processing.
  • CSV, XML and JSON file processing.

Goutte is a screen scraping and web crawling library for PHP built on top of Symfony components (HttpClient, DomCrawler, BrowserKit). It provides a simple, elegant API for navigating websites, submitting forms, and extracting data.

Note: Goutte is deprecated as of 2023. Its functionality has been merged into Symfony's HttpBrowser component. For new projects, use Symfony HttpClient with DomCrawler directly. Goutte is still included here because it remains widely used in existing codebases and many tutorials reference it.

Key features include:

  • Simple scraping API Combines HTTP client and DOM crawler into a single interface. Navigate pages, click links, and extract content with a clean, chainable API.
  • CSS selector support Uses Symfony DomCrawler's filter() and each() methods with CSS selectors for extracting data from HTML.
  • Form handling Can find, fill in, and submit HTML forms. Handles all standard input types including file uploads.
  • Cookie management Automatically manages cookies across requests within a session.
  • Guzzle integration Uses Guzzle HTTP client under the hood for reliable HTTP communication with proxy support, authentication, and custom headers.
  • Link crawling Can follow links by text or CSS selector, making multi-page scraping straightforward.

For new PHP scraping projects, consider using Symfony HttpClient + DomCrawler directly, or the Roach framework for a more feature-complete solution.

Highlights


popularcss-selectors

Example Use


// create scraper object
$web = new \Spekulatius\PHPScraper\PHPScraper;
// go to URL
$web->go('https://test-pages.phpscraper.de/content/selectors.html');

// elements can be found using XPath:
echo $web->filter("//*[@id='by-id']")->text();   // "Content by ID"

// or pre-defined variables covering basic page data:
$web->links;  // for all links
$web->headings;
$web->images;
$web->contentKeywords;
$web->orderedLists;
$web->unorderedLists;
$web->paragraphs;
$web->outline;  // basic page outline
$web->cleanOutlineWithParagraphs;  // basic page outline
<?php
require 'vendor/autoload.php';

use Goutte\Client;

$client = new Client();

// Navigate to a page
$crawler = $client->request('GET', 'https://example.com');
echo $crawler->filter('title')->text();

// Extract data using CSS selectors
$crawler->filter('.product')->each(function ($node) {
    $name = $node->filter('.name')->text();
    $price = $node->filter('.price')->text();
    echo "$name: $price\n";
});

// Click a link
$link = $crawler->selectLink('Next Page')->link();
$crawler = $client->click($link);

// Fill in and submit a form
$crawler = $client->request('GET', 'https://example.com/login');
$form = $crawler->selectButton('Login')->form([
    'username' => 'user@example.com',
    'password' => 'password123',
]);
$crawler = $client->submit($form);

// Cookies are maintained automatically across requests
echo $crawler->filter('h1')->text(); // "Welcome back!"

Alternatives / Similar


Was this page helpful?