FriendsOfPHP / Goutte

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

How to set proxy in new version? #407

Open ingen2 opened 4 years ago

ingen2 commented 4 years ago

Hi I want use http proxy in new version of Goutte client. How to set proxy in new version?

restucciaquito commented 4 years ago

Hi

I'm using like this:

use Goutte\Client; use Symfony\Component\HttpClient\HttpClient; $client = new Client(HttpClient::create(['proxy' => $proxy]));

And it's working. In any case, test it.

Hopes this help.

libellux commented 4 years ago

@restucciaquito I tried the above and I receive a HttpClient error that the proxy couldn't connect to the TARGET_URL not the proxy itself. However any tip would is appreciated.

Symfony\Component\HttpClient\Chunk\ErrorChunk::isFirst :64
vendor/symfony/http-client/Chunk/ErrorChunk.php:64
Symfony\Component\HttpClient\Exception\TransportException
Couldn't connect to server for TARGET_URL
acollazo25 commented 4 years ago

For recent versions use: Goutte Client instance (which extends Symfony\Component\BrowserKit\HttpBrowser)

use Symfony\Component\HttpClient\HttpClient;
use Goutte\Client;

$client = new Client(HttpClient::create(['proxy' => 'http://xx.xx.xx.xx:80']));
...
popouille commented 4 years ago

@restucciaquito I tried the above and I receive a HttpClient error that the proxy couldn't connect to the TARGET_URL not the proxy itself. However any tip would is appreciated.

Symfony\Component\HttpClient\Chunk\ErrorChunk::isFirst :64
vendor/symfony/http-client/Chunk/ErrorChunk.php:64
Symfony\Component\HttpClient\Exception\TransportException
Couldn't connect to server for TARGET_URL

Hello, Same error there. Whats wrong with that: use Symfony\Component\HttpClient\HttpClient; use Goutte\Client;

$client = new Client(HttpClient::create(['proxy' => 'http://xx.xx.xx.xx:80']));