Goutte PHP Web Scraping: Install, Extract, Follow Links, Submit Forms
Goutte is a small PHP client built for reading HTML pages: it sends HTTP requests, exposes the response as a Crawler, and lets you pick elements with CSS selectors. This guide walks through the two workflows most PHP scrapers need — pulling a list of links from a static page and driving a search form on a page that responds to input — and ends with the deprecation caveat you should weigh before building on it.
What Goutte is and what it is not
Goutte wraps an HTTP client and a DOM crawler. You call request() with an HTTP method and a URL, and you get back a Crawler object representing the returned HTML. From there, filter() takes a CSS selector and each() iterates over matches. text() reads visible text from a node, attr() reads an attribute such as href, and selectLink(), click(), selectButton() and submit() let you move through links and forms without hand-building URLs.
It is not a JavaScript runtime. If the data you want only appears after client-side rendering, Goutte will not see it. It is also not a proxy or anti-bot layer — it does not rotate IPs or solve CAPTCHAs. Treat it as a lightweight HTML reader for pages whose content is already in the response body.
Prerequisites and install
You need Composer and PHP 7.1 or newer. Confirm the PHP version first, then create a project directory (the walkthrough uses php-scraping) and add the library with Composer. The install command is shown in the protected module code0002; the PHP version check is in code0001. After installation, fabpot/goutte appears as a required dependency in composer.json, as illustrated in code0003, and the walkthrough expects version 4.
A quick sanity check before writing scrapers: run php --version and confirm it reports 7.1 or higher. If Composer is missing, install it from the official Composer download page first.
Static page walkthrough: Hacker News titles and links
The first example collects article titles and their links from Hacker News and writes them to a CSV. The workflow has five steps, and each step maps to a protected code module you can read alongside this section.
- Create web-static-scraper.php in the project directory.
- Require vendor/autoload.php and import Goutte\Client (code0004).
- Instantiate the client: $client = new Client(); (code0005).
- Send a GET request to https://news.ycombinator.com/ and keep the returned Crawler (code0006).
- Filter .titleline, read text() for the title and the inner a href for the link, collect pairs into $data (code0007 shows the HTML shape; code0008 shows the extraction).
- Write the header row Title, Link and each data row with fputcsv(), then close the file (code0009).
The complete file is code0010, and the run command is code0011. The output is a CSV in the data/ directory with one row per matched title element.
A useful habit: open the target page in a browser, right-click the element you want, and Inspect to confirm the class name before writing the selector. In this case the class is titleline, and the anchor inside it holds the article URL.
Dynamic page walkthrough: searching hockey team stats
The second example drives a search form on Scrape This Site to pull Dallas Stars statistics since 1990. The steps are sequential because each click returns a new Crawler.
- Create hockey-team-data.php.
- Require the autoloader, import Goutte\Client, and instantiate the client (code0012).
- GET https://www.scrapethissite.com/ (code0013).
- Click the Sandbox link: $client->click($crawler->selectLink('Sandbox')->link()) (code0014).
- Click the Hockey Teams: Forms, Searching and Pagination link (code0015).
- Select the Search button and get the form: $crawler->selectButton('Search')->form() (code0016).
- Submit with the team name in the q field: $client->submit($form, ['q' => 'Dallas Stars']) (code0017).
- Filter .team, read each td with trim(text()), collect rows, and write a CSV with the header row Team Name, Year, Wins, Losses, OT Losses, Win %, Goals For (GF), Goals Against (GA), + / - (code0018).
The complete file is code0019 and the run command is code0020. The output is data/team.csv with one row per matched team element.
Field/control map for this form: the button label is Search; the input name is q; the submitted value is the team name string. If you change the target site, re-inspect the form and update both the button label and the input name — a mismatch on either will fail at the selectButton() or submit() step, not at the filter step.
Decision checklist before you build
Use this short checklist to pick the right shape for your script:
- Is the data already in the HTML response? If yes, a single request() plus filter() is enough.
- Do you need to reach a page through a link on another page? Use selectLink() + click() and keep the returned Crawler.
- Do you need to submit a search or filter form? Use selectButton() + form() + submit(), and confirm the input name via Inspect.
- Do you need JavaScript-rendered content, rotating proxies, or CAPTCHA handling? Goutte does not provide these; plan a different tool for that layer.
- Are you starting a new project? Read the deprecation note below before committing to Goutte.
Deprecation and migration
Goutte is deprecated. It now acts as a proxy for the HttpBrowser class in Symfony's BrowserKit component, and the Goutte team recommends migrating away from it. That does not mean existing scripts stop working, but it does mean new work should plan for the migration path: BrowserKit's HttpBrowser plus a DOM crawler such as symfony/dom-crawler covers the same request/filter/click/submit surface.
A practical migration order: keep your selectors and form field names, swap the client for HttpBrowser, and re-run the same CSV export to confirm row counts match before deleting the Goutte dependency.
Frequently asked questions
What PHP version does Goutte need?
PHP 7.1 or higher. Check with php --version before installing.
How do I install Goutte?
Run composer require fabpot/goutte inside your project directory. It adds fabpot/goutte to composer.json as a required dependency.
How do I follow a link with Goutte?
Select the link by its visible text with selectLink(), pass its link() to click(), and keep the returned Crawler for the next step.
How do I submit a search form with Goutte?
Get the form with selectButton('Search')->form(), then call $client->submit($form, ['q' => 'Dallas Stars']). The q key must match the input's name attribute.
Is Goutte still maintained?
Goutte is deprecated and now proxies Symfony BrowserKit's HttpBrowser. The Goutte team recommends migrating away from it.
Can Goutte scrape JavaScript-rendered pages?
No. Goutte reads the HTML returned by the HTTP request; content that only appears after client-side rendering is not visible to it.
{
"require": {
"fabpot/goutte": "^4.0"
}
}