FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Cannot get response status code #389

Closed andrii-trush closed 4 years ago

andrii-trush commented 4 years ago

Hello. I'm trying to get url returns 404 error.

$goutteClient = new Client();
$response = $goutteClient->setHeader('User-Agent', $userAgent)->setClient($guzzleClient)->request('GET', 'https://example.com');

$response is instance of Symfony\Component\DomCrawler\Crawler

So, how can I get status for checking it is 404?

stof commented 4 years ago

$goutteClient->getResponse() will give you the Response object of the last request being done (and you should rename your $response variable, which is not the response.