Reputation: 15070
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.
Upvotes: 2
Views: 6395
Reputation: 7456
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.
Upvotes: 5
Reputation: 42959
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.
Upvotes: 3