不知道这样写怎么样,参考了这篇文章 https://blog.csdn.net/Innovation_Z/article/details/51106601?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-2.control
有一点错误!!!
################定义函数,报错重新下载 ##############
def auto_down(k,website,dirfilename):
while k<=15:
print(k)
try:
urllib.request.urlretrieve(website,dirfilename)
except error.ContentTooShortError:
print( ‘网络环境不好.重新下载.’)
k += 1
auto_down(k,website,dirfilename)
except error.URLError:
print(‘error.URLError报错,重新下载’)
k += 1
auto_down(k,website,dirfilename)
if k>15:
print(“下载失败”)