import requests
import os
url = 'https://t9.baidu.com/it/u=86853839,3576305254&fm=79&app=86&size=h300&n=0&g=4n&f=jpeg?sec=1585915817&t=f88ca17bad61a614771a86d9a45a9a0d'
root = 'F://pic// '
path = root + url.split('/')[-1]
try:
if not os.path.exists(root):
os.mkdir(root)
if not os.path.exists(path):
r = requests.get(url)
with open(path,"wb") as f:
f.write(r.content)
f.close()
print("图片爬取成功")
else:
print('文件已经存在')
except:
print('爬取失败')