python爬取图片失败

源代码如下:

import requests
import os
url = "http://img0.dili360.com/ga/M02/01/FA/wKgBy1Q2wYSAMsRrAAQKeoIdhoY918.jpg"
root = "D://image//"
path = root + url.split('/')[-1]
try:
	if not os.path.exists(root):
		os.mkdir(root)
	if not os.path.exixts(path):
		r = requests.get(url)
		with open(path, 'wb') as f:
			f.write(r.content)
			f.close()
			print("文件保存成功")
	else:
		print("文件已存在")
except:
	print("爬取失败")

 

题主失败的原因:exists单词拼写错误。

建议:调试bug时把try...catch...语句块给注释掉,这样就能根据报错的提示快速定位到错误