vendredi 22 janvier 2021

Creating a loop for URLs in python

I am trying to create a list of URL using for loop using the command. It is working also and giving all the URL but is not saving in a list as URL variable contains only 'https://Here is a URL/P2016-17.xls' and I want to have all the URL.

I am assuming using if into for will not give the desired output. But what else could have be done. Main objective is to download multiple files using URL RETRIEVE. Thanks in advance.

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 command 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, Command

url

gives only

https://Here is a URL/P2016-17.xls'

Aucun commentaire:

Enregistrer un commentaire