goutte - Goutte GuzzleHttpClient`403 Forbidden`响应
问题描述
我是 PHP Web Scraper 的新手,我正在使用Goutte
,GuzzleHttpClient
为此,许多网站给出 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();
解决方案
推荐阅读
- vb.net - .NET 继承的标签不会自动调整大小
- macos - lipo - 当指定 -thin 选项时,输入文件必须是 fat 文件
- node.js - 如何克服猫鼬中的路径要求错误
- javascript - 如何解决 VS 代码中的“npm run babel”错误?
- python - 如何在 scikit learn 中指定和搜索最佳行和列采样率?
- sql - 服务器上的服务启动和停止
- jenkins - Jenkins 保存提交的作者并监听推送
- excel - CountA:在 VBA 中给出错误的输出
- python-3.x - 我被 GurobiError 困扰:无法将参数转换为表达式
- python - 如何根据 tsne 集群输出将图像分成文件夹?