在 Goutte 中设置代理 [英] Setting proxy in Goutte

查看:30
本文介绍了在 Goutte 中设置代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 Guzzle 的文档来设置代理,但它不起作用.Goutte 的官方 Github 页面已经死了,所以在那里找不到任何东西.

I've tried using Guzzle's docs to set proxy but it's not working. The official Github page for Goutte is pretty dead so can't find anything there.

有人知道怎么设置代理吗?

Anyone know how to set a proxy?

这是我试过的:

$client = new Client();
$client->setHeader('User-Agent', $user_agent);
$crawler = $client->request('GET', $request, ['proxy' => $proxy]);

推荐答案

我已经解决了这个问题 =>

I have solved this problem =>

    $url = 'https://api.myip.com';
    $client = new \Goutte\Client;
    $client->setClient(new \GuzzleHttp\Client(['proxy' => 'http://xx.xx.xx.xx:8080']));
    $get_html = $client->request('GET', $url)->html();
    var_dump($get_html);

这篇关于在 Goutte 中设置代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆