Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get VariationsSummary for parent ASIN? #130

Open
SHxKM opened this issue Jan 27, 2018 · 1 comment
Open

How to get VariationsSummary for parent ASIN? #130

SHxKM opened this issue Jan 27, 2018 · 1 comment

Comments

@SHxKM
Copy link

SHxKM commented Jan 27, 2018

So basically I'm trying to write a script that will check for the availability of a currently-out-of-stock item.

Here's the URL of the product page:

https://www.amazon.com/Adidas-Originals-Primeknit-Trainers-Sneakers/dp/B07177WSCC/ref=sr_1_2?s=apparel&ie=UTF8&qid=1517048725&sr=1-2&nodeID=7147441011&psd=1&keywords=adidas+Originals+Men%27s+Stan+Smith+OG+PK+Fashion+Sneaker

Parent ASIN: B01N8TRZDX

Getting the child-product ASIN directly from the page would be ideal, but for color-size combos that aren't available, Amazon will redirect to a different color with the selected size. This changes the ASIN in all href links.

Basically, I want to get the child ASIN that is a specific color and size (say, White-white, size 8.5 US), but I can't seem to extract the variation part using the wrapper in order to extract it.

Any ideas?

@ThomasProctor
Copy link

ThomasProctor commented Mar 28, 2018

Unfortunately, it seems like this package doesn't currently support what you want explicitly. I opened a feature request (#133) for a few elements of the Amazon API that are also not supported.

You can use it to get the raw variations XML result using the keyword arg ResponseGroup='Variations'. I've been doing something similar with "AlternativeVersions", which gives different versions of books, and then processing it using lxml.etree (this package depends on it, so you should already have it installed).

Here's how you'd get your raw xml and get the etree node. You can learn how to further process XML like this in various tutorials.

(Note that I haven't actually tested the etree code here)

import os
from lxml import etree
from amazon.api import AmazonAPI
get = os.environ.get
amazon = AmazonAPI(get("AMAZON_ACCESS_KEY"),
                   get("AMAZON_SECRET_KEY"),
                   get("AMAZON_ASSOC_TAG"))
sneaker_result = amazon.lookup(ItemId="B01N8TRZDX",
                               IdType='ASIN',
                               ResponseGroup='Variations')
raw_xml = sneaker_result.to_string()
root = etree.fromstring(raw_xml)
root.find("{*}VariationsSummary")

You can navigate through the long list of variations and pick out all the child ASINs and availability statuses of offers using the etree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants