Python 亚马逊产品 Api 无法获取图像

Python Amazon Product Api not able to get image

我正在使用 python amazon product api,但我似乎无法获得产品图片的 url。

到目前为止,这是我的代码

for book in amz_api.item_search('Books', Keywords='cookies', ResponseGroup='Large', limit=10):
        print book.ItemAttributes.Large

但是我收到了这个回复

AttributeError: no such child: {http://webservices.amazon.com/AWSECommerceService/2011-08-01}Large

如有任何帮助,我们将不胜感激

要访问图像 URL,您可以尝试更改代码以使用以下之一:

print book.SmallImage.URL
print book.MediumImage.URL
print book.LargeImage.URL

错误是因为ItemAttributes中没有"Large"属性。图片 URL 在响应的不同部分可用。

Large Response Group (ResponseGroup='Large') returns a lot of data. According to the docs it's for demonstration purposes and not intended for production applications. To make your code production ready, you might need a different approach, such as the Images Response Group (ResponseGroup='Images').

另外,上面代码中book变量的python类型是:

<type 'lxml.objectify.ObjectifiedElement'>

调试时,您可以使用如下方式查看书中可用的所有数据:

from lxml import objectify

print(objectify.dump(book))