views:

60

answers:

2

Hi everybody,

I'm using CURL to extract some real estate listings. But, recently, a website changed his way to communicate the phone number: The visitor must click on a "Show the phone number" link that returns the result in jSon. I found these information with Firebug:

http://www.realestate.com/phone/click.json?Id=023DSFS

And for the linkn the code source is (obiously):

<a href="#" class="showDetail">Show the phone number</a>

So, how can I simulate a click and put store my result in a php var?

Thank you,

Regards.

+3  A: 

You can't "simulate a click" using cURL - the "show phone number" function persumably runs on client side in Javascript - and, I might add, was probably designed to prevent exactly the kind of cheapskate grabbing like you are doing. :D

You would have to parse the JavaScript code and find the JSON URL. Making a call to that URL using cURL is probably going to be easy, although you may have to get your headers right.

Seeing as they could be changing the principles behind that phone URL daily, though, this could become very tough to keep up with.

Unicron
+1  A: 

Maybe you can simply do

$var = json_decode(file_get_contents($url));

This is assuming allow_url_fopen = On and you don't need to have specific cookies for the http request to return the results.

SirDarius
He'll have to find that URL first, it seems to be hidden somewhere in the JS code.
Unicron
Thanks for your answer.I opted for this solution because the url that leads to the json file is absolute. So, the file_get_contents work perfectly ;)
Zakaria