对于请求建立缓存,加速重复请求

    https://requests-cache.readthedocs.io/en/stable/index.html

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