when iterating through the cell if a blank cell comes up, and error pops up and stop download. is there any exception or steps to ignore a blank cell?
for j in u.iteritems():
file_name = str(i) ".jpeg"
res = requests.get(u[0], stream = True)
if res.status_code == 200:
with open(file_name,'wb') as f:
shutil.copyfileobj(res.raw, f)
print('Image sucessfully Downloaded: ',file_name)
else:
print('Image Couldn\'t be retrieved')
CodePudding user response:
try adding a try: ..., except: continue block (or try:..., except: pass block) something like this:
for j in u.iteritems():
try:
file_name = str(j) ".jpeg"
res = requests.get(u[0], stream = True)
if res.status_code == 200:
with open(file_name,'wb') as f:
shutil.copyfileobj(res.raw, f)
print('Image sucessfully Downloaded: ',file_name)
else:
print('Image Couldn\'t be retrieved')
except:
continue