CodePak
CodePak

Reputation: 113

URL loop in python

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']

Upvotes: 0

Views: 96

Answers (2)

Abdusalam mohamed
Abdusalam mohamed

Reputation: 378

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)

Upvotes: 0

Ice
Ice

Reputation: 462

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

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

for asin in asins:
    url = URL_TEMP.format(asin)
    print(url)

Upvotes: 1

Related Questions