I have written the following code to save an album from a website.
import urllib2
import webbrowser
import os
page=1564848
fileno=1
for fileno in range(1,24):
pages=str(page)
filenos=str(fileno)
picture_page = "url-to-the-website"+pages+".jpg"
page=page+1
os.chdir("/home/comrider/Album/")
if not os.path.exists("3"):
os.makedirs("3")
os.chdir("/home/user/Album/3")
try:
opener1 = urllib2.build_opener()
page1 = opener1.open(picture_page)
my_picture = page1.read()
filename = filenos + picture_page[-4:]
fileno=fileno+1
fout = open(filename, "wb")
fout.write(my_picture)
fout.close()
except:
fileno=fileno-1 #This statement is not working
pass
Since there are missing image number i have given a try and except statement and in the except statement I have given a statement to decrement the file no. that was incremented in the try statements. But that code is not working resulting in incomplete downloading of the album. The working platform is linux. Please help. thanks in advance.
filenowill be reset on the next loop iteration, you can change it to whatever you want but when the current for loop iteration ends it will increment from1..24from the docs:
rangereturns a list sequence you are progressing along that sequenceif you need to mess with your counter you could use a while loop