dpea85385 2016-09-29 08:35
浏览 185

如何从亚马逊产品广告API中获取功能

I'm using Amazon Product advertising API and fetching product details by using its ASIN value. I'm getting data in XML format but have an issue assesing the features of products.

<?xml version="1.0"?>
-<ItemLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01">
+<OperationRequest>
-<Items>
-<Item> 
<ASIN>B01G9VYRWU</ASIN>  
<ParentASIN>B01D4FCID4</ParentASIN>
<DetailPageURL>http://www.amazon.co.uk/Unlocked-Smartphone-Android-MT6580-HotKnot/dp/B01G9VYRWU%3Fpsc%3D1%26SubscriptionId%3DAKIAJVHGJYQC2HPM3LHQ%26tag%3Dhogmall-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB01G9VYRWU</DetailPageURL>
+<ItemLinks>
+<SmallImage>
+<MediumImage>   
+<LargeImage>
+<ImageSets>
-<ItemAttributes>
<Binding>Electronics</Binding>
<Color>Gold</Color> 
<Feature>POWERFUL 4150 mAh BATTERY: Tired of bringing a power bank everywhere? Then enjoy the long battery life of this handset. When you are traveling, using the built-in GPS on Google map is power -hungry. Don't worry about of running out power in outdoor any more. Even heavy user don't need to charge this cell phone everyday!</Feature>

<Feature>3G DUAL SIM SMARTPHONE: 3G: WCDMA 900/1900/2100MHz, also support 2g: GSM 850/900/1800/1900MHz. Compatible with lots of Carriers like Vodafone, O2, EE, T-mobile, Three, giffgaff, Lebara, CTExcelbiz, Lyca, Talk home Mobile......Two micro sim slots allow you to combine both work and personal use on the same handset or use one sim in UK. One slot is for micro sim card, another is for micro sim card or micro SD card up to 32GB of extended storage.</Feature>

<Feature>BUDGET PHONE WITH HIGH TECH SPECIFICATION: It has fast Quad Core 1.3 GHz Processor running on good Android 5.1 Lollipop system, 2GB RAM and 5.5 inch HD screen. Games, apps, web browsing, movies and everything else will run fantastically quickly on Note S.</Feature>

<Feature>COOL CAMERA: With an interpolated 8MP auto focus camera featuring an LED flash and interpolated 5MP wide-angle front camera, you'll have the confidence to capture shots even in challenging conditions. Face front camera let you enjoy video talk on whatsapp, Skype and take great selfies. Experience a crisp and bright viewing experience, even in direct sunlight, with a super sharp 5.5" HD display that sits elegantly in a precision crafted, diamond cut sleek frame.</Feature>

<Feature>SAFE GUARANTEE: Our Cubot smartphones have CE and ROHS certification. All handsets are environmental-friendly.And we offer 1 year guarantee free repair and return for phone itself serious quality problem</Feature>

<Label>CUBOT</Label>
<Manufacturer>CUBOT</Manufacturer>
<Model>166711601</Model>
<MPN>166711601</MPN>
-<PackageDimensions>   
<Height Units="hundredths-inches">291</Height> 
<Length Units="hundredths-inches">732</Length>   
<Weight Units="hundredths-pounds">119</Weight> 
<Width Units="hundredths-inches">441</Width>  
</PackageDimensions>
<PackageQuantity>1</PackageQuantity>
<PartNumber>166711601</PartNumber> 
<ProductGroup>Wireless</ProductGroup> 
<ProductTypeName>PHONE</ProductTypeName> 
<Publisher>CUBOT</Publisher>  
<Studio>CUBOT</Studio> 
<Title>CUBOT NOTE S Unlocked 3G 5.5'' Smartphone Dual Sim Smartphone Android 5.1 MT6580 Quad Core 1.3GHz Mobile Phone 2GB RAM+16GB ROM Dual SIM HotKnot (Gold)</Title>   
</ItemAttributes>
+<OfferSummary>
+<Offers>
</Item>  
</Items>
</ItemLookupResponse>

To fetch the features I'm using below code

$response = simplexml_load_file($request_url);
if(isset($response->Items->Item)){
            echo 'yes';

            //$asin = $response->Items->Item->ASIN;
            if(in_array($id, $json)){ //if id is in features array then continue

                //if(isset($response->Items->Item->ItemAttributes)){
                    echo '<br>Features<br>';
                    foreach($response->Items->Item as $item){
                        foreach($item->ItemAttributes->Feature as $fea){
                            echo 'features '.trim($fea).'<br>';
                            $value = str_replace("'", "%", trim($fea));//replaced " with ! because giving error in sql query
                            $value = str_replace('"', "!", trim($fea));
                            if($value != '' || $value != NULL){
                                $duplicate .= '("'.trim($id).'", "'.trim($asin).'", "'.trim($value).'" ) ,';
                                $sql_features .= '("'.trim($id).'", "'.trim($asin).'", "'.$value.'" ) ,';
                            }

                            echo $sql_features .'<br>';

                        }

                    }
            }

        }

But I'm not able to get features of products.

  • 写回答

1条回答 默认 最新

  • ds19891231 2016-09-29 08:47
    关注

    Your $sql_features variable, may out of scope, try this way

     if($value != '' || $value != NULL){
       $duplicate .= '("'.trim($id).'", "'.trim($asin).'", "'.trim($value).'" ) ,';
       $sql_features .= '("'.trim($id).'", "'.trim($asin).'", "'.$value.'" ) ,';
    
       // echo it inside if
       echo $sql_features .'<br>';
       }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)