requests爬虫简单框架:
import requests try: r = requests.get(url) r.raise_for_status() #如果状态码不是200会异常 r.encoding = r.apparent_encoding return r.text except: return ‘产生异常
path=r‘c:/abc.jpg‘ open(path, ‘wb‘)
会报错:PermissionError: [Errno 13] Permission denied: ‘c:/abc.jpg‘
path=r‘c:/1/abc.jpg‘ open(path, ‘wb‘)
就不会。。。不明白
path = r‘c:/1/abc.jpg with open(path, ‘wb‘) as f: f.write(r.content)
关于content和text:https://www.jianshu.com/p/0e0336b370f3