import requests as req
import os
url = input('请输入图片地址:')
#url = 'https://img.haomeiwen.com/i2256672/958f31b01695b085.gif'
root = 'e://pic//'
path = root + url.split('/')[-1]
try:
if not os.path.exists(root):
os.mkdir(root)
if not os.path.exists(path):
r = req.get(url)
with open(path,'wb') as f:
f.write(r.content)
f.close()
print('文件保存成功')
else:
print('文件已存在')
except:
print('爬取错误')
网友评论