import requests
import os
#下载图片到指定的位置
def download_imgs(root,file_name,img_url):
try:
if not os.path.exists(root):
os.mkdir(root)
if not os.path.exists(root + file_name):
re = requests.get(img_url)
re.raise_for_status()
#
with open(root + file_name,'wb') as f:
f.write(re.content)
print('照片下载成功')
except:
print('图片下载失败')