标签:jpg port path requests exist for _for 网页 status
1、图片爬取代码
import requests import os root = "H:/美图/" url = "https://k.zol-img.com.cn/sjbbs/7692/a7691501_s.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) r.raise_for_status() with open(path, "wb") as f: f.write(r.content) f.close() print("文件保存成功") else: print("文件已经存在") except: print("爬取失败")
标签:jpg port path requests exist for _for 网页 status
原文地址:https://www.cnblogs.com/nxrs/p/11031017.html