学习网络爬虫课,抄了一段爬图片的代码,换了百度上的图片链接,下载的图片只有1.4K,还打不开
import requests
import os
url="https://lmg.jj20.com/up/allimg/1011/102QG32938/1G02Q32938-5-1200.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("爬取失败")
运行显示,文件已保存,但是图片只有1.4K,还打不开
尝试换其他图片的链接,还是一样的结果
你这个url对应的资源不存在了