Page 1 of 1

file_get_contents trouble

Posted: Fri Sep 02, 2011 8:39 pm
by chuckbalzer
Hi,

I'm loading google search results with

Code: Select all

$cocntents = file_get_contents("http://www.google.com/products/catalog?q=036725235182&hl=en&cid=6520112632679181641&os=sellers#scoring=tp");
I want the results to be sorted by total price, hence #scoring=tp

What is weird is that if I take the link and copy it into a new browser window it displays the results exactly as I would like to see them.

but if I echo $cocntents the page does not sort by total price. It sorts by the default Relevance. So my script see the page sorted incorrectly.

Does anyone know how I can get around this? Maybe a different load method or different approach all together? Thanks in advance for the help.

Chuck

Re: file_get_contents trouble

Posted: Fri Sep 02, 2011 9:58 pm
by 2-d
Hey there,

I think the issue has to do with how the site works. The part after hash (#) is part of their javascript. Whats actually happening on that site, is the normal order is displaying on load, then they have some javascript to parse out the variables after the # and then load the order.

I don't believe file_get_contents will parse any javascript, you are just getting the flat file. So it will always be in the default order. If you turn off javascript on your browser and then go to that site, you should see the same order you are getting through your script.

You may need to just parse it out and then sort in your script.

Best of luck.