我发现设置代理服务器有两种方法,一种是通过chrome Web驱动程序功能,另一种是在创建chrome客户端时直接设置
$this->client = Client::createChromeClient(null, [
'--proxy-server=socks://196.14.52.63:35048',
'--headless',
"--disable-gpu",
]);
但是在设置代理IP和端口后,我收到以下错误:
Curl error thrown for http POST to /session/cce06908d68a1e96bc6d1cb3b798aa14/url with params: {"url":"https://some-site/login"}n
Operation timed out after 30001 milliseconds with 0 bytes received
基本上我想使用代理服务器,同时使用Symfony panther抓取数据。
我让它通过传递以下配置。
$this->client = Client::createChromeClient(null, [
'--window-size=1200,1100',
"--proxy-server=http://ip:port",
'--headless',
"--disable-gpu",
]);
我认为以前我使用的代理服务器不支持HTTPS(我试图访问HTTPS页面(,而且我也缺少Windows大小的参数。
有时代理可能需要很长时间才能响应,并且您尝试访问的站点可能需要超过 30 秒的时间。您可以尝试像这样增加您的时间:
Client::createChromeClient(base_path('drivers/chromedriver'), $args, ["port" => 9080, 'request_timeout_in_ms' => 100000]);