Skip to content Skip to sidebar Skip to footer

Get All Image Urls From Amazon Api

You can use this code to get the first image URL of one specific item on amazon: from amazon.api import AmazonAPI amazon = AmazonAPI(aws_key='XXX', aws_secret='XXX', aws_associate

Solution 1:

You need to include the 'Images' response group in your request.

product = amazon.lookup(ItemId='B003P0ZB1K', ResponseGroup='Images')

The list of XML ImageSets can then be accessed via the images property, but will need to be parsed using an XML parser.

product.images

Please check out this article for information on parsing XML in python: How do I parse XML in Python?

Reference: https://docs.aws.amazon.com/AWSECommerceService/latest/DG/RG_Images.html

From the source code of the library:

@propertydefimages(self):
    """List of images for a response.
    When using lookup with RespnoseGroup 'Images', you'll get a
    list of images. Parse them so they are returned in an easily
    used list format.
    :return:
        A list of `ObjectifiedElement` images
    """try:
        images = [image for image in self._safe_get_element(
            'ImageSets.ImageSet')]
    except TypeError:  # No images in this ResponseGroup
        images = []
    return images

The image set XML looks like this:

<ImageSets><ImageSetCategory="primary"><SwatchImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L._SL30_.jpg</URL><HeightUnits="pixels">30</Height><WidthUnits="pixels">23</Width></SwatchImage><SmallImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L._SL75_.jpg</URL><HeightUnits="pixels">75</Height><WidthUnits="pixels">58</Width></SmallImage><ThumbnailImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L._SL75_.jpg</URL><HeightUnits="pixels">75</Height><WidthUnits="pixels">58</Width></ThumbnailImage><TinyImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L._SL110_.jpg</URL><HeightUnits="pixels">110</Height><WidthUnits="pixels">86</Width></TinyImage><MediumImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L._SL160_.jpg</URL><HeightUnits="pixels">160</Height><WidthUnits="pixels">124</Width></MediumImage><LargeImage><URL>https://ecx.images-amazon.com/images/I/51YL4rlI%2B9L.jpg</URL><HeightUnits="pixels">500</Height><WidthUnits="pixels">389</Width></LargeImage></ImageSet></ImageSets>

Post a Comment for "Get All Image Urls From Amazon Api"