I have been looking for a graceful way to dynamically format strings (URLs) in Python while looping... This is for when I want to request using different query parameters for each.
For example, this is what I've been resorting to at the moment (assuming I have 3 URLs):
for i in range(3):
for num in range(0, 496, 5):
if i == 1:
requests.get('https://my-website.com?pricefrom={}&priceto={}'.format(num, num + 5))
if i == 2:
requests.get('https://my-website.com?qtyfrom={}&qtyto={}'.format(num, num + 5))
# ......... :(
This is just ugly and I don't want to imagine what I'd do in the scenario where I have more links to request to.
Isn't there a solution simpler/more graceful like this for example:
urls = [<url1>, <url2>,....<url50>] # maybe each url has placeholders
for url in urls:
# do some magic
Any help would be highly appreciated
requests.get()let you pass the arguments as a dictionnary ? docs.python-requests.org/en/master/user/quickstart/…