Пример 1.4. archive.py
1 import webbrowser
2 import json
3 from urllib.request import urlopen
4
5 print("Let's find an old website.")
6 site = input("Type a website URL: ")
7 era = input("Type a year, month, and day, like 20150613: ")
8 url = "" % (site, era)
9 response = urlopen(url)
10 contents = response.read()
11 text = contents.decode("utf-8")
12 data = json.loads(text)
13 try:
14 old_site = data["archived_snapshots"]["closest"]["url"]
15 print("Found this copy: ", old_site)
16 print("It should appear in your browser now.")
17 webbrowser.open(old_site)
18 except:
19 print("Sorry, no luck finding", site)