php - Images download using Goutte -
i have download images using cookie in request. make file_get_contents (with stream_context_create) or curl passing cookies. how make goutte?
use goutte\client; $client = new client(); $response = $client->request('get', 'https://www.google.pl/images/srpr/logo11w.png');
i make request , what's next step?
ok, figured out:
$client->get('https://www.google.pl/images/srpr/logo11w.png', array('save_to' => __dir__.'/image.jpg'));
with goutte 2:
$client = new guzzlehttp\client([ 'base_url' => 'https://www.google.pl', 'defaults' => [ 'cookies' => true, ] ]); $response = $client->post('/login', [ 'body' => [ 'login' => $login, 'password' => $password ] ]); $response = $client->get('/images/srpr/logo11w.png'); $image = $response->getbody();
with goutte 1 after adding "guzzle/plugin-cookie": "~3.1" composer:
use guzzle\http\client; use guzzle\plugin\cookie\cookieplugin; use guzzle\plugin\cookie\cookiejar\arraycookiejar; $client = new client('https://www.google.pl'); $client->addsubscriber(new cookieplugin(new arraycookiejar())); $response = $client->post('/login', '', array('login' => $login, 'password' => $password))->send(); $response = $client->get('/images/srpr/logo11w.png')->send(); $image = $response->getbody();
Comments
Post a Comment