Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Crawler Laravel Package

spatie/crawler

PHP web crawler that discovers links concurrently via Guzzle, with optional JavaScript rendering powered by Chrome/Puppeteer. Configure depth, internal-only rules, and callbacks for per-page handling, plus a fake mode to test crawl logic without real HTTP requests.

View on GitHub
Deep Wiki
Context7

title: Custom request handlers weight: 3

The crawler uses two handler classes to process Guzzle pool results: one for fulfilled requests and one for failed requests. You can replace these with your own subclasses to customize how responses and errors are processed.

Custom fulfilled handler

Create a class that extends CrawlRequestFulfilled:

use Psr\Http\Message\ResponseInterface;
use Spatie\Crawler\Handlers\CrawlRequestFulfilled;

class MyFulfilledHandler extends CrawlRequestFulfilled
{
    public function __invoke(ResponseInterface $response, mixed $index): void
    {
        // your custom logic here

        parent::__invoke($response, $index);
    }
}

Then pass it to the crawler:

use Spatie\Crawler\Crawler;

Crawler::create('https://example.com')
    ->fulfilledHandler(MyFulfilledHandler::class)
    ->start();

Custom failed handler

Create a class that extends CrawlRequestFailed:

use Exception;
use Spatie\Crawler\Handlers\CrawlRequestFailed;

class MyFailedHandler extends CrawlRequestFailed
{
    public function __invoke(Exception $exception, mixed $index): void
    {
        // your custom logic here

        parent::__invoke($exception, $index);
    }
}

Then pass it to the crawler:

use Spatie\Crawler\Crawler;

Crawler::create('https://example.com')
    ->failedHandler(MyFailedHandler::class)
    ->start();

The class you pass must extend the base handler class. If it doesn't, an InvalidCrawlRequestHandler exception will be thrown.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle