import requests
import os
url="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1495098953,1880040495&fm=26&gp=0.jpg"
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("爬取失败")
图片爬取
猜你喜欢
转载自blog.csdn.net/qq_39926861/article/details/104769979
今日推荐
周排行