import requests
import os
url = "http://img0.dili360.com/ga/M02/32/FE/wKgBzFSORXuACp8AABXyQnlRi7U325.tub.jpg@!rw9"#图片地址
root = "D://pics//"
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("爬取失败")
``
Python中使用requests库爬取网络图片
最新推荐文章于 2024-05-13 07:33:35 发布