FriendsOfPHP / Goutte

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

Scrap JSON data #384

Open ajay-patidar opened 5 years ago

ajay-patidar commented 5 years ago

Hello,

I'm calling a URL that returns JSON, So how can I get that JSON response?

Thanks

seuaCoder commented 4 years ago

$crawler = $client->request('GET', 'https://url.com'); $crawler->html();

should return your json

Noneatme commented 4 years ago

$crawler = $client->request('GET', 'https://url.com'); $crawler->html();

should return your json

PHP Fatal error: Uncaught InvalidArgumentException: The current node list is empty.

jmichaelterenin commented 4 years ago

$client->getResponse()->getContent()

Haritsinh commented 4 years ago

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.