Quickstart: Crawl a website and handle responses
mainUse Crawler::create() to initialize a crawl starting from a specific URL. You can use the onCrawled() method to register a callback that executes whenever a page is successfully crawled. This callback receives the URL as a string and a CrawlResponse object, which you can use to inspect the response (e.g., checking the HTTP status code). Call start() to begin the process.
use Spatie\
Crawler\\Crawler;
use Spatie\\Crawler\\CrawlResponse;
Crawler::create('https://example.com')
->onCrawled(function (string $url, CrawlResponse $response) {
echo "{$url}: {$response->status()}\n";
})
->start();