对于请求建立缓存,加速重复请求
import requests
import requests_cache
requests_cache.install_cache('demo_cache')
requests.get('http://httpbin.org/delay/1')
# <Response [200]>
requests.get('http://httpbin.org/delay/1')
'''
CachedResponse(_content=b'{\n "args": {}, \n "data": "", \n "files": {}, \n "form": {}, \n "headers": {\n "Accept": "*/*", \n
"Accept-Encoding": "gzip, deflate", \n "Host": "httpbin.org", \n "User-Agent": "python-requests/2.20.0", \n "X-Amzn-Trace-
Id": "Root=1-620e13e4-08c7331d01cda15c7a87eb40"\n }, \n "origin": "39.102.38.22", \n "url": "http://httpbin.org/delay/1"\n}\n', _ne
xt=None, cookies=<RequestsCookieJar[]>, created_at=datetime.datetime(2022, 2, 17, 9, 22, 45, 508157), elapsed=datetime.timedelta(secon
ds=1, microseconds=598133), encoding=None, expires=None, headers={'Date': 'Thu, 17 Feb 2022 09:22:45 GMT', 'Content-Type': 'applicatio
n/json', 'Content-Length': '355', 'Connection': 'keep-alive', 'Server': 'gunicorn/19.9.0', 'Access-Control-Allow-Origin': '*', 'Access
-Control-Allow-Credentials': 'true'}, history=[], reason='OK', request=CachedRequest(body=b'None', cookies=<RequestsCookieJar[]>, head
ers={'User-Agent': 'python-requests/2.20.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive'}, method=
'GET', url='http://httpbin.org/delay/1'), status_code=200, url='http://httpbin.org/delay/1')
'''