Goutte
Goutte copied to clipboard
Scrap JSON data
Hello,
I'm calling a URL that returns JSON, So how can I get that JSON response?
Thanks
$crawler = $client->request('GET', 'https://url.com');
$crawler->html();
should return your json
$crawler = $client->request('GET', 'https://url.com');$crawler->html();should return your json
PHP Fatal error: Uncaught InvalidArgumentException: The current node list is empty.
$client->getResponse()->getContent()
Response will ne in string so for using it you have to convert it into object or array using json decode function as provided in your server language as in php the function is json_decode which convert json string to object:
$result = json_decode($client->getResponse()->getContent());
Now you can iterate over $result object.