Mink is a free, open source data extraction & web scraping project written in PHP and released under MIT. It has 1,608 GitHub stars, 286 forks and 79 open issues, and was last pushed 1 months ago. On this registry it ranks #83 of 125 tracked projects in Data Extraction & Web Scraping, with 5 head-to-head comparisons available.

What is Mink?

Mink is a PHP library that gives developers a single, driver-agnostic interface for driving and interrogating web pages through interchangeable browser-emulation sessions, aimed at PHP teams writing tests and scraping workflows.

What it is

Mink is an abstraction layer written in PHP and distributed as the Composer package behat/mink. It sits between your application code and the concrete mechanism that fetches and renders a page, presenting both through the same Session object. A Mink instance holds one or more named sessions, each constructed from a driver — for example new Session(new GoutteDriver(new GoutteClient()), 'goutte2') — and a default session can be designated with setDefaultSessionName() so that a bare getSession() call returns it.

The problem it solves is that PHP code which navigates a site, clicks links, and reads page content would otherwise have to be rewritten whenever the underlying fetcher changes. By routing everything through getSession()->getPage() methods such as findLink('Downloads')->click() and getContent(), the same script works against a Goutte-backed session, a custom driver such as MyCustomDriver($startUrl), or any other driver plugged into the abstraction. Because sessions are addressed by name, several can coexist in one process and be used interchangeably.

Key capabilities

  • Holds multiple named sessions in a single Mink instance, so getSession('goutte1') and getSession('goutte2') return distinct active contexts within one script.
  • Sets a default session via setDefaultSessionName('goutte2'), letting getSession() with no argument resolve to the configured default.
  • Drives pages through a uniform page API: getPage()->findLink('Downloads')->click() and getPage()->getContent() work the same regardless of driver.
  • Wraps the Goutte fetcher through GoutteDriver and GoutteClient, giving a non-browser HTTP-based session out of the box.
  • Accepts user-supplied drivers directly, as illustrated by MyCustomDriver($startUrl) in the usage example.
  • Supports mixing sessions in sequence, visiting and clicking within goutte1, goutte2, and custom sessions in the same run.
  • Is installed as the Packagist package behat/mink, with stable and unstable versions published and download counts tracked on Packagist.

Who uses it and how

  • PHP teams that write browser-driven tests, since the project lives in the Behat orbit — documentation is hosted at https://mink.behat.org/ and support is handled through the Behat Google Group.
  • Developers who navigate a site programmatically: the README flow visits a start URL, follows a link by its text, and reads back the resulting page content.
  • Projects that need more than one fetching context at once, running a Goutte-backed session alongside a custom session and switching between them by name within one script.
  • Contributors maintaining driver integrations, with three named lead developers (everzet, stof, aik099) and an active CI workflow at .github/workflows/tests.yml.
  • Consumers tracking library stability through Packagist badges for the latest stable version, unstable version, total downloads, and license.

Getting started

Install the Composer installer and run php composer.phar install in the project to pull in the dependencies; the library itself is behat/mink on Packagist.

How it compares

Mink integrates with Goutte through GoutteDriver and GoutteClient while still permitting a driver of your own design, so it does not commit a codebase to one fetcher. No comparable abstraction tools are named in the available facts, so Mink stands alone in this registry as the project of its kind described here.

When to use it — and when not

You must supply a driver yourself or depend on one such as GoutteDriver, so a user needs a working PHP environment with Composer-managed dependencies and no self-hosted service to operate. It is not the right pick for those outside the PHP ecosystem, and readers should note the 79 open issues alongside the MIT licence when judging maturity before adopting it.

project readme (upstream, from github) — read inline

Mink

Latest Stable Version Latest Unstable Version Total Downloads CI License

Useful Links

Usage Example

<?php

use Behat\Mink\Mink,
    Behat\Mink\Session,
    Behat\Mink\Driver\GoutteDriver,
    Behat\Mink\Driver\Goutte\Client as GoutteClient;

$startUrl = 'http://example.com';

// init Mink and register sessions
$mink = new Mink(array(
    'goutte1' => new Session(new GoutteDriver(new GoutteClient())),
    'goutte2' => new Session(new GoutteDriver(new GoutteClient())),
    'custom'  => new Session(new MyCustomDriver($startUrl))
));

// set the default session name
$mink->setDefaultSessionName('goutte2');

// visit a page
$mink->getSession()->visit($startUrl);

// call to getSession() without argument will always return a default session if has one (goutte2 here)
$mink->getSession()->getPage()->findLink('Downloads')->click();
echo $mink->getSession()->getPage()->getContent();

// call to getSession() with argument will return session by its name
$mink->getSession('custom')->getPage()->findLink('Downloads')->click();
echo $mink->getSession('custom')->getPage()->getContent();

// this all is done to make possible mixing sessions
$mink->getSession('goutte1')->getPage()->findLink('Chat')->click();
$mink->getSession('goutte2')->getPage()->findLink('Chat')->click();

Install Dependencies

$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar install

Contributors

Frequently asked questions

Is Mink free to use?

Mink is open source under the MIT licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does Mink do?

PHP web browser emulator abstraction

What is Mink written in?

Mink is primarily written in PHP. Its source is publicly available at https://github.com/minkphp/Mink, and it has 1,608 GitHub stars.