Handy classes for Spatie's crawler when using it with Laravel.
spekulatius/spatie-crawler-toolkit-for-laravel is a Laravel package for handy classes for spatie's crawler when using it with laravel..
It currently has 20 GitHub stars and 964 downloads on Packagist (latest version 0.5.0).
Install it with composer require spekulatius/spatie-crawler-toolkit-for-laravel.
Discover more Laravel packages by spekulatius
or browse all Laravel packages to compare alternatives.
Last updated
A set of classes to use Spatie's crawler with Laravel. Aim is to simplify building crawler applications or adding a crawler to an existing Laravel project. It can be conveniently integrated into PHP Scraper, for example. At the moment the following helper classes are implemented:
The CacheCrawlQueue allows use the pre-configured Cache in Laravel to store the queue. It stores any actions performed on the queue directly to avoid the need to manually store the queue. You can add it directly to your crawler:
Crawler::create()
->setCrawlQueue(new \Spekulatius\SpatieCrawlerToolkit\Queues\CacheCrawlQueue($url))
->startCrawling($url);
With this you can stop the crawl and restart at any time. This requires a cache-driver being configured in your .env file.
The Crawl Logger is an observer you can add to your crawler to enable logging of crawl events:
Crawler::create()
->setCrawlObserver(new \Spekulatius\SpatieCrawlerToolkit\Observers\CrawlLogger)
->startCrawling($url);
You can export the configuration (see below) to tweak which events are logged.
The toolkit contains an observer to send you Laravel events allowing you to react to crawl events. This covers the following events:
By default, no events are emitted. To enable events, you will need to add the event observer to your crawler:
$eventObserver = new \Spekulatius\SpatieCrawlerToolkit\Observers\CrawlEvents;
Crawler::create()
->setCrawlObserver($eventObserver)
->startCrawling($url);
An optional identifier can be passed to the crawl events to distinguish between different crawls:
$eventObserver = new \Spekulatius\SpatieCrawlerToolkit\Observers\CrawlEvents('my-crawl');
For any suggestions on how to enhance this, please raise an issue.
composer require spekulatius/spatie-crawler-toolkit-for-laravel
Optionally, you can publish the configuration file:
php artisan vendor:publish --tag=crawler-toolkit-config
Please raise a PR or issue.
Released under the MIT license. Please see License File for more information.