简体   繁体   English

Python Amazon Product Api无法获取图像

[英]Python Amazon Product Api not able to get image

I'm using python amazon product api and I can't seem to get the url for the image of the product. 我正在使用python亚马逊产品api ,但似乎无法获取产品图片的网址。

Here is my code so far 到目前为止,这是我的代码

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

But I get this reply 但是我得到这个回复

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

Any help would be apprecicated 任何帮助将不胜感激

To access the image URLs, you can try to change your code to use one of the following: 要访问图像URL,您可以尝试将代码更改为使用以下之一:

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

The error is because there is no "Large" attribute in ItemAttributes . 该错误是因为ItemAttributes中没有“ Large”属性。 The image URLs are available in a different part of the response. 图像URL在响应的不同部分中可用。

The Large Response Group (ResponseGroup='Large') returns a lot of data. 大响应组 (ResponseGroup ='Large')返回大量数据。 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'). 为了准备好代码生产,您可能需要其他方法,例如图像响应组 (ResponseGroup ='Images')。

Also, the python type for the book variable in the above code is: 另外,上述代码中book变量的python类型是:

<type 'lxml.objectify.ObjectifiedElement'>

While debugging, you can look at all the data available in book using something like this: 调试时,您可以使用以下方式查看书中可用的所有数据:

from lxml import objectify

print(objectify.dump(book))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM