I'm working on pricing script which uses data from local comparison shopping engine called zbozi.cz and I would like to ask you about how to get prices (and more) from it. However it returns me HTML file with javascript - and in the javascript codes there are needed data.
For example - I have a PHP array with data like this - http://pastebin.com/BjBtYMv4 - and there are about 10-20 codes like this in the array.
What do I need? Any library or something? I need to "translate" those javascript data into PHP array and after I'll save it into the MySQL database and process it with another script. It should be really fast because I need to process about 80 000 codes like this a day.
BTW - sometimes there are more / less whitespaces in this code, so the solution should be able to process everything.
Hope I have described my problem enough (my English restriction).
EDIT: I found this - Parsing Javascript (not JSON) in PHP - but it doesn't work for me :(
EDIT2: It works until "clickthruData" appear, so just one question - could you please make script which edit the code from paste bin to work with script in the EDIT above?
-
"I have an PHP array with data like this - pastebin.com/BjBtYMv4" - You one you linked is a JavaScript array mind you! Also, it's 100% JSONP encoding you'll need. Most modern browsers have encoding/decoding functions where libraries are not needed like the one you posted (2009).MackieeE– MackieeE2013年10月13日 19:46:26 +00:00Commented Oct 13, 2013 at 19:46
2 Answers 2
The Javascript you have posted looks like a JSON variable.
Assuming you could cut off everything before an opening curly bracket { and a closing curly bracket }, you should be able to use PHP JSON functions to handle this.
7 Comments
JSON_ERROR_SYNTAX - gotta workout if you have escaped quotes somewhere etc{label: 'item_featured', productName: is where it's failing, label and poductName haven't got quotes around them, they must do.$data = str_replace('},', ',', $data); =)var opt = {'id': 'itemRow-0',
'url': 'http://www.videotech.cz/audio-video/dj-technika/.../',
'cp': '5B9DN0UD-qzuhuuvvKKZjg==' };
var encodedOpt = JSON.stringify( opt );
Then within your PHP file that was sent with the variable of encodedOpt,
<?php
$decodedJson = json_decode( encodedOpt );
?>