我有一个简单的问题,因为没有找到任何答案。实际上我可以使用亚马逊的API从ASIN代码获取有关产品的信息,但在这个图像的情况下,我可以得到不同格式的单个图像,大拇指,中间拇指等,对吧?
在我的情况下,我想知道是否有可能从产品中获取所有图像,不仅显示不同格式的1张图片,如果我可以使用scrapp获取所有图像,但在这种情况下我想使用API,因为它使用scrapp
来解决CURL的许多查询问题实际上我使用它:
$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);
项目结构:
$item = $xml->Items->Item;
$title = htmlentities((string) $item->ItemAttributes->Title);
$url = htmlentities((string) $item->DetailPageURL);
$image = htmlentities((string) $item->MediumImage->URL);
$price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$amount=htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$item->OfferSummary->LowestUsedPrice->Amount);
$code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
$qty = htmlentities((string) $item->OfferSummary->TotalNew);
$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);
功能API代码:
function getAmazonPrice($region, $asin)
{
global $precioamz;
global $amountamz;
global $imageamz;
global $galeriaamz;
$xml = aws_signed_request($region, array(
"Operation" => "ItemLookup",
"ItemId" => $asin,
"IncludeReviewsSummary" => False,
"ResponseGroup" => "Medium,OfferSummary",
));
$item = $xml->Items->Item;
$title = htmlentities((string) $item->ItemAttributes->Title);
$url = htmlentities((string) $item->DetailPageURL);
$image = htmlentities((string) $item->MediumImage->URL);
$price = htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$amount=htmlentities((string) $item->OfferSummary->LowestNewPrice->Amount);
$item->OfferSummary->LowestUsedPrice->Amount);
$code = htmlentities((string) $item->OfferSummary->LowestNewPrice->CurrencyCode);
$qty = htmlentities((string) $item->OfferSummary->TotalNew);
$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL);
/// $gallery=Images,ItemAttributes,Variations,VariationImages
if ($qty !== "0")
{
$response = array(
"code" => $code,
"price" => number_format((float) ($price / 100), 2, '.', ''),
"image" => $image,
"url" => $url,
"title" => $title,
"amount" => $amount,
"galeria" => $gallery
);
}
$precioamz=$response['price'];
$amountamz=$response['amount'];
$imageamz=$response['image'];
$galeriaamz=$response['galeria'];
//return $response;
}
function getPage($url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$html = curl_exec($curl);
curl_close($curl);
return $html;
}
但是只获得1张图片,我想获得此产品的所有图片,感谢您的帮助,问候
答案 0 :(得分:0)
如果我没有误解您的要求,我认为您从Amazon API文档页面https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingImages.html获取的Amazon API XML respsnse就是这样的。因此,您可以尝试这种方式获取所有图像网址。
$xmlstr = <<<XML
<Item>
<ASIN>B004HO6I4M</ASIN>
<SmallImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">56</Width>
</SmallImage>
<MediumImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg
</URL>
<Height Units="pixels">160</Height>
<Width Units="pixels">120</Width>
</MediumImage>
<LargeImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg
</URL>
<Height Units="pixels">500</Height>
<Width Units="pixels">375</Width>
</LargeImage>
<ImageSets>
<ImageSet Category="primary">
<SwatchImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL30_.jpg
</URL>
<Height Units="pixels">30</Height>
<Width Units="pixels">22</Width>
</SwatchImage>
<SmallImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">56</Width>
</SmallImage>
<ThumbnailImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">56</Width>
</ThumbnailImage>
<TinyImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL110_.jpg
</URL>
<Height Units="pixels">110</Height>
<Width Units="pixels">82</Width>
</TinyImage>
<MediumImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg
</URL>
<Height Units="pixels">160</Height>
<Width Units="pixels">120</Width>
</MediumImage>
<LargeImage>
<URL>
https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg
</URL>
<Height Units="pixels">500</Height>
<Width Units="pixels">375</Width>
</LargeImage>
</ImageSet>
</ImageSets>
</Item>
XML;
$images = new SimpleXMLElement($xmlstr);
$image_set = $images->ImageSets->ImageSet;
$all_images = [];
foreach($image_set->children() as $key=>$value){
$all_images[$key] =trim((string)$value->URL);
}
print '<pre>';
print_r($all_images);
print '</pre>';
输出
Array
(
[SwatchImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL30_.jpg
[SmallImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
[ThumbnailImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL75_.jpg
[TinyImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL110_.jpg
[MediumImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL160_.jpg
[LargeImage] => https://ecx.images-amazon.com/images/I/519SgX2wwDL._SL500_.jpg
)
答案 1 :(得分:0)
要获取您必须使用的所有图像,或添加
当您致电Images,ItemAttributes,Variations,VariationImages
时, ResponseGroup
作为请求密钥aws_signed_request()
的值
我当然希望你现在得到一个不同的响应,所以你的响应解析代码可能需要修改。
检查响应并相应地编辑代码。