After a very deep search inside the Goutte libraries, I found a way and I wanted to share it. Because Goutte is a really powerful library, but there is so much documentation.
Parsing JSON via (Goutte> Guzzle)
Just get the desired output page and save json to an array.
$client = new Client(); // Goutte Client $request = $client->getClient()->createRequest('GET', 'http://***.json'); /* getClient() for taking Guzzle Client */ $response = $request->send(); // Send created request to server $data = $response->json(); // Returns PHP Array
JSON parsing with cookies via (Goutte + Guzzle) - for authentication
Send a request to one of the pages of the site (the main page looks better) to receive cookies, and then use these cookies for authentication.
$client = new Client(); // Goutte Client $crawler = $client->request("GET", "http://foo.bar"); /* Send request directly and get whole data. It includes cookies from server and it automatically stored in Goutte Client object */ $request = $client->getClient()->createRequest('GET', 'http://foo.bar/baz.json'); /* getClient() for taking Guzzle Client */ $cookies = $client->getRequest()->getCookies(); foreach ($cookies as $key => $value) { $request->addCookie($key, $value); } /* Get cookies from Goutte Client and add to cookies in Guzzle request */ $response = $request->send(); // Send created request to server $data = $response->json(); // Returns PHP Array
Hope this helps. Because I almost spent 3 days to understand Gouttle and its components.
source share