首页 > 解决方案 > Goutte GuzzleHttpClient`403 Forbidden`响应

问题描述

我是 PHP Web Scraper 的新手,我正在使用GoutteGuzzleHttpClient为此,许多网站给出 200 作为响应,除了https://www.leboncoin.fr/返回 403 Forbidden。我尝试了许多建议的解决方案,但响应是 403,这是我的最终代码:

<?php
require 'vendor/autoload.php';

$goutteclient=new \Goutte\Client();
$guzzleClient  = new \GuzzleHttp\Client();
$resource = $guzzleClient->request('GET', 'https://www.leboncoin.fr/', [
    'referer' => true,
    'headers' => [
        'User-Agent' => 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36',
        'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
            'Accept-Encoding' => 'gzip, deflate, br',
        ],

    ]);
// return 403 Forbidden
echo $resource->getStatusCode();

标签: goutte

解决方案


推荐阅读