0

I have been working with two APIs to fetch data from amazon.com. Using first API I am getting a series of ASINs (string) and now need to pass first 10 ASINs to second API URL to fetch "Product Description".

I am getting ASINs from first API in below format. All strings

B07BJL8CL2
B00CA6X50Y
B01LI4IDQO
B000HTENO8
B00XKXNGT6

Second API URL querystring_lookupProduct = {"url":"https://www.amazon.com/dp/B09BVQPNWZ"}

I have to dynamically replace the end part B09BVQPNWZ with ASINs I am getting from first API. Would really appreciate your help.

One is to convert ASIN in list but as I try to do this I get the response like this

['B', '0', '7', 'B', 'J', 'L', '8', 'C', 'L', '2']
['B', '0', '0', 'C', 'A', '6', 'X', '5', '0', 'Y']
['B', '0', '0', 'X', 'K', 'X', 'N', 'G', 'T', '6']
['B', '0', '1', 'L', 'I', '4', 'I', 'D', 'Q', 'O']
1
  • 1) create a list of strings with ASIN (asin_to_fetch), then 2) iterate over this list: for asin in asin_to_fetch: ... and 3) use string formatting to build the desired URL: url="https://www.amazon.com/dp/{}".format(asin) Commented Jan 6, 2022 at 6:24

2 Answers 2

1
URL_TEMP = "https://www.amazon.com/dp/{}"

asins = ['B07BJL8CL2', 'B00CA6X50Y', 'B01LI4IDQO', 'B000HTENO8', 'B00XKXNGT6']

for asin in asins:
    url = URL_TEMP.format(asin)
    print(url)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply however when I try to convert the asins in list using asin=list(asin) I am getting it in this format ['B', '0', '7', 'B', 'J', 'L', '8', 'C', 'L', '2'], ['B', '0', '7', 'B', 'J', 'L', '8', 'C', 'L', '2'] ['B', '0', '0', 'C', 'A', '6', 'X', '5', '0', 'Y'] ['B', '0', '0', 'X', 'K', 'X', 'N', 'G', 'T', '6'] ['B', '0', '1', 'L', 'I', '4', 'I', 'D', 'Q', 'O']
asin is not a string?
0
url = 'https://www.amazon.com/dp/'
Dict = []// create a list to hold the urls


asins = ['B07BJL8CL2', 'B00CA6X50Y', 'B01LI4IDQO', 'B000HTENO8', 'B00XKXNGT6']

// iterate over the asins and populate your list with the values

For asin in asins:
   Dict.append(url + '/' + asin)

2 Comments

Thanks for the reply however when I try to convert the asins in list using asin=list(asin) I am getting it in this format ['B', '0', '7', 'B', 'J', 'L', '8', 'C', 'L', '2']
When asin is a string using the list func will break it down to characters, try changing the " for asin in asins " to " for i < count(asins) " and then using asin[i] as an index

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.