【爬虫入门】【正则表达式】抓取白敬亭贴吧某个帖子下的图片2.0

在原有基础上添加异常处理模块,防止访问正则表达式提取的东西的时候出现异常

修改def getImg (html)函数
def getImg(html):
    #此处修改
    for imgurl in imglist:
        try:
            urllib.request.urlretrieve(imgurl, '{}{}.jpg'.format(paths, "bai'jing" + str(x)))  # 打开imglist中保存的图片网址,并下载图片保存在本地,format格式化字符串
        except Exception as e:
            pass
        x = x + 1
    return imglist
	

猜你喜欢

转载自blog.csdn.net/qq_37252519/article/details/86073111
今日推荐