Skip to content

panthervsgoutte

MIT 215 4 3,072
22.6 thousand (month) Jul 17 2018 v2.4.0(2026-01-08 05:29:21 ago)
9,164 2 137 MIT
Dec 02 2012 8.5 thousand (month) v4.0.3(2023-04-01 09:05:33 ago)

Panther is a convenient standalone library to scrape websites and to run end-to-end tests using real browsers.

Panther is super powerful. It leverages the W3C's WebDriver protocol to drive native web browsers such as Google Chrome and Firefox.

Panther is very easy to use, because it implements Symfony's popular BrowserKit and DomCrawler APIs, and contains all the features you need to test your apps. It will sound familiar if you have ever created a functional test for a Symfony app: as the API is exactly the same! Keep in mind that Panther can be used in every PHP project, as it is a standalone library.

Panther automatically finds your local installation of Chrome or Firefox and launches them, so you don't need to install anything else on your computer, a Selenium server is not needed!

In test mode, Panther automatically starts your application using the PHP built-in web-server. You can focus on writing your tests or web-scraping scenario and Panther will take care of everything else.

Features:

  • executes the JavaScript code contained in webpages
  • supports everything that Chrome (or Firefox) implements
  • allows taking screenshots
  • can wait for asynchronously loaded elements to show up
  • lets you run your own JS code or XPath queries in the context of the loaded page
  • supports custom Selenium server installations
  • supports remote browser testing services including SauceLabs and BrowserStack

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


<?php

use Symfony\Component\Panther\Client;

require __DIR__.'/vendor/autoload.php'; // Composer's autoloader

$client = Client::createChromeClient();
// Or, if you care about the open web and prefer to use Firefox
$client = Client::createFirefoxClient();

$client->request('GET', 'https://api-platform.com'); // Yes, this website is 100% written in JavaScript
$client->clickLink('Get started');

// Wait for an element to be present in the DOM (even if hidden)
$crawler = $client->waitFor('#installing-the-framework');
// Alternatively, wait for an element to be visible
$crawler = $client->waitForVisibility('#installing-the-framework');

echo $crawler->filter('#installing-the-framework')->text();
$client->takeScreenshot('screen.png'); // Yeah, screenshot!
<?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?