<?php

namespace App\Command;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;
use Spatie\Crawler\CrawlObservers\CrawlObserver;

class TestClass extends CrawlObserver
{
    public function willCrawl(UriInterface $url, ?string $linkText): void
    {
        echo "即将爬取: {$url}\n";
    }

    public function crawled(
        UriInterface $url, ResponseInterface $response, ?UriInterface $foundOnUrl = null, ?string $linkText = null): void {
        var_dump($response);
        echo "已成功爬取: {$url} 状态码: " . $response->getStatusCode() . "\n";
    }

    public function crawlFailed(UriInterface $url, \Throwable $exception, ?UriInterface $foundOnUrl = null, ?string $linkText = null): void
    {
        echo "爬取失败: {$url} 错误: {$exception->getMessage()}\n";
    }
}