2017-12-30 12 views
1

간단한 질문이 있으니 답을 찾으셔야합니다. 사실 나는 ASIN 코드의 제품에 대한 정보를 얻기 위해 Amazon's API를 사용할 수 있지만,이 이미지의 경우에는 다른 형식, 하나의 큰 이미지, 중간 정도의 엄지 손가락 등을 얻을 수 있습니까?Amazon API는 제품에서 모든 이미지를 가져옵니다

제 경우에는 제품에서 모든 이미지를 가져올 수 있는지 알고 싶습니다. 스크래프를 사용하여 모든 이미지를 가져올 수 있다면 다른 형식으로 표시하지 말고,이 경우에는 API를 사용하고 싶습니다.

$gallery=htmlentities((string) $item->ImageSets->ImageSet->LargeImage->URL); 

항목 구조 :

사실 내가 이것을 사용 더 깨끗하고 S와 CURL에서 많은 쿼리와 haven't 문제 scrapp

를 사용하여

기능 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; 
} 

만 한 이미지를 얻고 난이 제품에서 모든 이미지를 얻을 원하는 도움말에 대한 thank's, 내가 오해하지 않는 경우

답변

0

에 관하여 귀하의 요구 사항, 아마존 API XML respsnse 아마존 API 설명서 페이지에서 가져온 것입니다 이런 가정합니다 https://docs.aws.amazon.com/AWSECommerceService/latest/DG/EX_RetrievingImages.html. 그래서이 방법으로 모든 이미지 URL을 얻을 수 있습니다.

$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 
) 
+0

@Jos는 내가 당신을 위해 일했는지 아닌지 알려주시겠습니까? –

+0

아니요, 제 질문에서 제품의 모든 이미지에 대해 이야기합니다. 아마존에서 제품을 보러 가면 다양한 이미지를 볼 수 있습니다. API에서 다른 크기 또는 해상도의 이미지 만 가져올 수 있습니다. 여기까지 넣을 수 있지만 제품에는 갤러리가 있습니다. 이미지, API에서 나는 같은 이미지가 아닌 제품의 모든 이미지를 보여주고 싶습니다. 실제로 파서로드 DOM 제품을 사용하여 웹 사이트를로드하고이 이미지와 데이터베이스를 표시 할 때 모든 이미지를 표시 할 수 있지만 문제는 아마존의 것입니다. API는 하나의 이미지 만 보여 주며, 다른 이미지는 아마존의 API 만 사용하여 표시 할 수 있는지 모르겠다. – Jos

0

이 사용하거나 호출 할 때 ResponseGroup 키 요청에 대한 값으로

Images,ItemAttributes,Variations,VariationImages을 추가 할 수있는 모든 이미지를 가져올 수 aws_signed_request()

물론 당신이 지금 얻고있는 것과는 다른 응답을 기대할 수 있습니다. ponse 구문 분석 코드를 수정해야 할 수도 있습니다.

응답을 검사하고 이에 따라 코드를 편집하십시오.

관련 문제