views:

28

answers:

3

Hi,

I'm looking for a way to extract some information from this site via PHP:

http://www.mycitydeal.co.uk/deals/london

There ist a counter where the time left is displayed, but the information is within the JavaScript. Since I'm really a JavaScript rookie, I didn't really know how to get the information.

Normally I would extract the information with "preg_match" and some regular expressions. Can someone help me to extract the information (Hrs., Min., Sec.) ?

Jennifer

+1  A: 

I hate to say "no", but in this situation PHP is not the right job for this. JavaScript requires a browser to run (in this case) and on top of that you probably have a jQuery lib.

The only thing PHP could do is invoke a browser that would contain some JavaScript (i.e., GreaseMonkey) that could try and scrape the page for the info. But this is really a job for embedded JavaScript.

webbiedave
+2  A: 

Extracting the count-down time is not going to be easy, because it is fetched and set purely using JavaScript, which cannot be parsed using pure PHP. You would have to de-code the JavaScript code and see what calls it makes to fetch the initial times.

That is not an easy process, and could be changed by the site owners in no time.

Also, doing that, you would be in clear breach of their T&C:

For the avoidance of doubt, scraping of the Website (and hacking of the Website) is not allowed.

Pekka
+1  A: 

As the others have said you can usually not access JavaScript stuff from PHP. However JavaScript has to get its data from somewhere, and this is where to start.

I found this in the source code:

<input type="hidden" id="currentTimeLeft" value="3749960"/>

That's the number of microsecond until whatever it is.

However this was only present in firefox, not when fetching it with wget. I found out it's the cookie that matters, so you'd have to request the page once, store the cookies and then access it a second time.

Marian
Nice catch. She could set her agent string to firefox and hopefully get the same data back.
webbiedave
Good catch! Didn't see that.
Pekka
@webbiedave: No, I tried that one first and it didn't work ;)
Marian