我使用亚马逊产品广告API并使用其ASIN值获取产品详细信息。我以XML格式获取数据,但在评估产品功能方面存在问题。
<?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>
使用以下代码
获取我的功能$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>';
}
}
}
}
但我无法获得产品功能。
答案 0 :(得分:0)
您的$ sql_features变量可能超出范围,请尝试这种方式
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>';
}