I’m trying to read the html from this page to later parse it. The problem is when I use file_get_contents($url), it misses some content (the content I actually need). For example, it doesn’t get the data after “Amounts per 1 ounce” (just a blank), and all the data (the numbers only, it does get the labels) in the “NUTRITION INFORMATION” tables.
Here’s the script:
<?php
$url = "http://nutritiondata.self.com/facts/fruits-and-fruit-juices/1848/2";
$content = file_get_contents($url);
var_dump($content);
?>
The URL you are requesting does not actually contain the data you’re looking for. The data you see in your browser is being put into the page via javascript.
Here’s what the page looks like without javascript:
You’ll need to find the datasource the javascript is using (which is probably some other URL entirely) and read that.
It looks like in this case, the data is actually in the page you’re requesting (just not where you’re looking for it), in a big JSON object around line 3400. Look for
foodNutrients = {