使用python-amazon-simple-product-api提取最低二手商品价格

1 投票
1 回答
904 浏览
提问于 2025-04-20 15:56

我正在学习用Python来提取二手书的价格,使用的是 python-amazon-simple-product-api 这个库。

这是我现在正在使用的代码:

amazon = AmazonAPI(aws_access_key, 
                   aws_secret_key,
                   aws_associate_key)

# products = amazon.search(Keywords=book_demanded_df['isbn01'].values[1], SearchIndex='Books')
products = amazon.search(Keywords='B00CU0NSCU', SearchIndex='All')

# print book_demanded_df['isbn01'].values[1]
for i, product in enumerate(products):
    print product.title
    print product.asin
    print product.get_attribute('Manufacturer')    
    print product.get_attributes(['ItemDimensions.Width', 'ItemDimensions.Height'])
    print product.offer_url

我觉得关键在于 get_attributes 这个部分,我尝试写了类似 ItemAttributes.Amount 的东西,但好像不太管用。

请问用这个API可以做到吗?

1 个回答

2

我是这个小库的作者。亚马逊的API返回的数据有点乱,而且根据你查询的产品不同,返回的内容也会有所不同。在上面的例子中,ASIN是属于Kindle Fire 7寸平板的一系列产品。这个系列有8GB和16GB两种内存版本,每个版本都有不同的ASIN。例如,8GB版本的ASIN是B007T36S34。

至于二手价格,目前API不支持这个功能,不过你可以用以下方法来解决:

>>> products[0]._safe_get_element_text(('OfferSummary.LowestUsedPrice.FormattedPrice'))
'$84.99'
>>> products[0]._safe_get_element_text(('OfferSummary.LowestUsedPrice.CurrencyCode'))
'USD'

在查找这类数据时,查看一下亚马逊产品广告API的文档会很有帮助。

撰写回答