blob: 0170d9b43f8db6decbfb65a5390f520c6a55fcae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import requests
import requests_cache
requests_cache.install_cache('example_cache')
def main():
# Once cached, delayed page will be taken from cache
# redirects also handled
for i in range(5):
requests.get('http://httpbin.org/delay/2')
r = requests.get('http://httpbin.org/redirect/5')
print(r.text)
# And if we need to get fresh page or don't want to cache it?
with requests_cache.disabled():
print(requests.get('http://httpbin.org/ip').text)
# Debugging info about cache
print(requests_cache.get_cache())
if __name__ == "__main__":
t = time.time()
main()
print('Elapsed: %.3f seconds' % (time.time() - t))
|