doukai1226 2016-02-06 17:19
浏览 259

获取Amazon Product API上的所有项目

Amazon's Product API limits us to get only 10 items per page, and only 10 pages at a certain query.

I have developed a code that would almost get all items; first, I have supplied a params that looks like this:

    $item_params = [
            "Service" => "AWSECommerceService",
            "Operation" => "ItemSearch",
            "AWSAccessKeyId"    => env('AWS_ACCESS_KEY_ID'),
            "AssociateTag"      => env('AWS_ASSOCIATE_TAG_ID'),
            "SearchIndex" => "HomeGarden",
            "ResponseGroup" => "ItemAttributes,SalesRank,Offers",
            "Sort" => "-price",
            "BrowseNode" => $item_params['BrowseNode'],
            "MaximumPrice" => $max_price,
            "MinimumPrice" => "0"
        ];

then, the code will get all items under that browse node (category), SORTED BY PRICE (desc) also by specifying the MAX and MIN Price of the items to limit the search.

the pseudo-code (original code is too long)

function getProducts($item_params, $max_price = null){

    $products = //request to amazon
    foreach ($product as $key=>$value){
       //add product to db
    }

    // if the total number of results on the query is not equal to zero, continue looping
    if (!$products->totalResults() == 0){
      $product = //get the first lowest priced item on the db

      $this->getProducts($item_params, $product->price);
    }

}

however I am experiencing this scenario :

Sample request output (assuming all items from amazon):

ASIN(unique id) | Price 

1     |  201
2     |  194
3     |  195
.
.
n     | 33
n+1   | 33
n+2   | 33
.    
n+120 | 33
n+121 | 34
n+122 | 35 

wherein the products from n to n+120 are equal. This will create an infinite loop to my getProducts function. How can I avoid this? Knowing that only 10 items are returned on each request and only 10 pages.

  • 写回答

2条回答 默认 最新

  • duannian4784 2016-02-08 16:01
    关注

    How can I avoid this?

    I don't think you can with just using price. You have to divide your search into multiple sub-searches by using additional keywords. For example, if you're searching for "laptop", instead do searches on "laptop asus", "laptop dell", etc.

    You can also filter on Browse node IDs, so if your results come from multiple browse nodes, you can do two or more searches.

    评论

报告相同问题?

悬赏问题

  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题