#-*- coding:UTF-8 -*- import requests import os def getImage(url): root = 'F:/image/' 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 '爬取失败' if __name__ == '__main__': url = 'http://www.5djiaren.com/uploads/allimg/160318/21_031Q523331155.jpg' getImage(url)
网络图片的爬取与存储
最新推荐文章于 2021-12-16 21:52:35 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)