如何使 python 忽略空白单元格并继续从下一个单元格下载图像

How to make python ignore a blank cell and continue downloading images from the next 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')

尝试添加一个 try: ..., except: continue 块(或 try:..., except: pass 块) 像这样:

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