简体   繁体   English

Xpath / XML / PHP

[英]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. 我将xpath ID和其他方面综合在一起,但它也会生成其他内容。 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'];
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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