I am trying to create a list of URLs using a for loop. It prints all the correct URLs, but is not saving them in a list. Ultimately I want to download multiple files using urlretrieve
.
for i, j in zip(range(0, 17), range(1, 18)):
if i < 8 or j < 10:
url = "https://Here is a URL/P200{}".format(i) + "-0{}".format(j) + ".xls"
print(url)
if i == 9 and j == 10:
url = "https://Here is a URL/P200{}".format(i) + "-{}".format(j) + ".xls"
print(url)
if i > 9:
if i > 9 or j < 8:
url = "https://Here is a URL/P20{}".format(i) + "-{}".format(j) + ".xls"
print(url)
Output of above code is:
https://Here is a URL/P2000-01.xls
https://Here is a URL/P2001-02.xls
https://Here is a URL/P2002-03.xls
https://Here is a URL/P2003-04.xls
https://Here is a URL/P2004-05.xls
https://Here is a URL/P2005-06.xls
https://Here is a URL/P2006-07.xls
https://Here is a URL/P2007-08.xls
https://Here is a URL/P2008-09.xls
https://Here is a URL/P2009-10.xls
https://Here is a URL/P2010-11.xls
https://Here is a URL/P2011-12.xls
https://Here is a URL/P2012-13.xls
https://Here is a URL/P2013-14.xls
https://Here is a URL/P2014-15.xls
https://Here is a URL/P2015-16.xls
https://Here is a URL/P2016-17.xls
But this:
url
gives only:
'https://Here is a URL/P2016-17.xls'
How do I get all the URLs, not just the final one?