2

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?

1
  • "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). Commented Oct 13, 2013 at 19:46

2 Answers 2

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
  • Thus, JSON_ERROR_SYNTAX - gotta workout if you have escaped quotes somewhere etc Commented Oct 13, 2013 at 20:06
  • I think the {label: 'item_featured', productName: is where it's failing, label and poductName haven't got quotes around them, they must do. Commented Oct 13, 2013 at 20:08
  • 1
    hehe, i've got it! used stackoverflow.com/questions/1554100/… and edited my string with $data = str_replace('},', ',', $data); =) Commented Oct 13, 2013 at 20:08
  • Coolio =) Good luck with the rest! Commented Oct 13, 2013 at 20:09
  • thank you man, I'm new to stackoverflow should I mark your answer as accepted? It's not the solution, but you helped me. Commented Oct 13, 2013 at 20:10
0
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 );
?>
1
  • I forgot to tell you it should work in the CLI mode. So I can't use JS. Commented Oct 13, 2013 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.