简体   繁体   中英

Xpath / XML / PHP

I am trying to extract price of the product from Amazon.

I pulled together the xpath ID and other aspects but it generates additional content as well. What I am trying to achieve is just pull the numbers along with the currency sign:

 http://webscrapemaster.com/api/?url=http://www.amazon.com/Canon-PowerShot-SX510-Digital-Optical/dp/B00EFILPHA//&xpath=//span[@id=priceblock_ourprice] 

Current output is

[{"text":"$188.99","attrs":{"id":"priceblock_ourprice","class":"a-size-medium a-color-price"}}]

What I need as the output is just:

$188.99

You can use this (transform into an array then get the value):

<?php
$json_data = '[{"text":"$188.99","attrs":{"id":"priceblock_ourprice","class":"a-size-medium a-color-price"}}]';
$array = json_decode($json_data,true);
$price = $array['text'];
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM