|
楼主 |
发表于 2018-12-18 17:59:43
|
显示全部楼层
https://timgsa.baidu.com/timgimage&quality=80&size=b9999_10000&sec=1545137043559&di=f393c6ef8d96a3faaf8df71ba9fed719&imgtype=0&src=http%3A%2F%2Fi0.hdslb.com%2Fbfs%2Farchive%2Fecd4bdaf4ca7932143ab4ac43136faf534567111.jpg
这种网址是不是爬不出来,就是右键检查元素的URL,然后用这个代码爬取失败,不知道哪里出错了
import requests
import os
url=""
root="E://hml//"
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("爬取失败") |
|