最简单的网络图片的爬取 --Pyhon网络爬虫与信息获取
生活随笔
收集整理的這篇文章主要介紹了
最简单的网络图片的爬取 --Pyhon网络爬虫与信息获取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、本次要爬取的圖片的url
http://www.nxl123.cn/static/imgs/php.jpg
2、代碼部分
import requestsimport os
url = "http://www.nxl123.cn/static/imgs/php.jpg"
root = "C:/Users/Niuxi/Desktop/pic/"#注意最后“/”帶上
path = root+url.split('/')[-1]
try:
if not os.path.exists(root):
os.makedirs(root)
if not os.path.exists(path):
r = requests.get(url)
# print(r.status_code)
with open(path,'wb') as f:
f.write(r.content)
f.close()
print("文件保存成功")
else:
print("文件已經存在");
except:
print("爬取失敗!")
3、打印結果
桌面上自動新建的文件夾:
轉載于:https://www.cnblogs.com/qikeyishu/p/9354868.html
總結
以上是生活随笔為你收集整理的最简单的网络图片的爬取 --Pyhon网络爬虫与信息获取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 7_23 day26 14min
- 下一篇: Educational Codeforc