#网络图片的爬取 import requests import os root = "D://pics//" url = "http://image.nationalgeographic.com.cn/2017/0211/20170211061910157.jpg" 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("shibai")
图片爬虫
最新推荐文章于 2024-07-22 17:25:13 发布