javascript - Can XPath be used to search a <script> block? -


i'm ok skills-wise @ selecting sorts of html content. confident creating code should ripping content of site stumbled across strange javascript code source puts prices in.

<script>  var productconfig = {"attributes":{"178":{"id":"178","code":"bp_flavour","label":"smaak","options":[{"id":"28","label":"aardbeien","oldprice":"0","products":["2292","2294","2296","2702"]} 

.... more gibberish , 4 of each product variation: (so 80 different lines this:)

,"childproducts":{ "2292":"price":"64.99","finalprice":"64.99","no_of_servings":"166","178":"27","179":"34"}, "2292":"price":"17.99","finalprice":"17.99","no_of_servings":"33","178":"28","179":"25"} }   </script> 

apparently 2292 id of product @ hand. read out "finalprice".

my php code:

    $file = $this->curl_get_file_contents($url);     $doc = new domdocument();    @$doc->loadhtml($file);     $doc->preservewhitespace = false;     $finder = new domxpath($doc);      $price_query = $finder->query("//script[contains(.,'finalprice')]");     $price_raw = $price_query->item(0)->nodevalue; 

however query //script[contains(.,"finalprice")] blasts out whole script cant find way dig deeper , more in javascript. know more/could give me hint?

you may try regular expression:

preg_match_all("/finalprice\\":\\"([0-9.]{1,10})\\"/", $page_html, $output_array); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -