helturkey / php-webtrawler
A PHP-first web scraping and crawling toolkit with adaptive extraction, concurrent spiders, and optional browser automation.
Requires
- php: ^8.4
- ext-dom: *
- ext-json: *
- ext-libxml: *
- ext-xmlwriter: *
- guzzlehttp/guzzle: ^7.9
- guzzlehttp/promises: ^2.0
- symfony/css-selector: ^7.4 || ^8.0
- symfony/dom-crawler: ^7.4 || ^8.0
Requires (Dev)
- amphp/http-client: ^5.0
- amphp/http-tunnel: ^2.0
- dekor/php-impity: ^1.0
- friendsofphp/php-cs-fixer: ^3.75
- orchestra/testbench: ^11.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5 || ^12.0
- playwright-php/playwright: ^1.6
Suggests
- ext-curl: Required for GuzzleTransport concurrent crawling through curl-multi; without it Guzzle remains blocking.
- ext-intl: Required to fetch internationalized (non-ASCII) host names such as https://example.com/.
- ext-mbstring: Faster, broader charset conversion for non-UTF-8 pages (iconv is used as a fallback).
- ext-pcntl: Lets `scraper crawl` stop cleanly on Ctrl-C / SIGTERM and save its resume state.
- ext-pdo_sqlite: Required by SQLiteSnapshotStore and SQLiteCrawlDeduplicator for optional persistent crawl deduplication.
- ext-posix: Enables ownership checks on browser-session directories.
- amphp/http-client: Optional concurrent AmpTransport on the Revolt event loop (amphp/http-client 5).
- amphp/http-tunnel: Optional HTTP CONNECT proxy support for AmpTransport.
- dekor/php-impity: Optional PSR-18 transport using curl-impersonate for browser-like TLS and HTTP/2 fingerprints. Requires the matching curl-impersonate binary.
- illuminate/support: Laravel 13 integration: service provider, Scrape facade, configuration and scraper:fetch command (Testbench 11.x in development tests).
- playwright-php/playwright: Optional Chromium automation for JavaScript rendering, browser sessions, and request/response capture. Requires Node.js 20+ and installed Playwright browsers.
Provides
None
Conflicts
None
Replaces
None
README
PHP Scraper is a PHP-first web scraping toolkit for HTTP fetching, DOM parsing, adaptive element matching, concurrent crawling, optional Chromium rendering, structured exports, a CLI, an MCP server, and Laravel integration.
Documentation
Choose your language:
- English: Full documentation —
docs/en - العربية: التوثيق الكامل —
docs/ar - Français / Español / Türkçe:
docs/fr·docs/es·docs/tr(quick starts) - Documentation language index
The documentation covers installation, fetching and parsing, HTTP security, adaptive selectors, spiders and resumability, transports and proxies, Playwright, CLI/MCP, Laravel, exporters, Docker deployment and CI, testing, troubleshooting, and API entry points.
Install
composer require helturkey/php-webtrawler
The core requires PHP 8.4+ and ext-dom, ext-json, ext-libxml, and ext-xmlwriter. Playwright, php-rnet, and Impity are optional integrations with additional requirements. See English requirements or المتطلبات بالعربية.
Minimal example
<?php declare(strict_types=1); use HElturkey\WebTrawler\Options\FetchOptions; use HElturkey\WebTrawler\Scraper; require __DIR__ . '/vendor/autoload.php'; $options = new FetchOptions( blockPrivateNetworks: true, allowedHosts: ['example.com'], maxBodyBytes: 10 * 1024 * 1024, ); $scraper = Scraper::create( defaultOptions: $options, enforceDefaultSecurity: true, ); $page = $scraper->get('https://example.com/'); echo $page->title() ?? 'Untitled';
Security note
For untrusted URLs, configure blockPrivateNetworks, an appropriate allowedHosts list, finite timeouts and a finite response-size limit, and set enforceDefaultSecurity: true. HTTP-level URL checks do not fully prevent DNS rebinding. Playwright routing is best-effort and is not a complete SSRF boundary; use network-level egress isolation for untrusted browser targets. See HTTP security and browser security.
Docker
The production runtime and unified AMD64 CI image are built from one Dockerfile. Run the complete Docker validation with:
composer test-docker
See the Docker deployment and CI guide or الدليل العربي.
Development checks
composer validate --strict
composer cs
composer stan
composer test
composer check
Optional integration commands and the full release checklist are documented in Testing and release and الاختبارات والإصدار.