1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
import requests
from eliot import start_action, to_file
to_file(open("linkcheck.log", "w"))
def check_links(urls):
with start_action(action_type="check_links", urls=urls):
for url in urls:
try:
with start_action(action_type="download", url=url):
response = requests.get(url)
response.raise_for_status()
except Exception as e:
raise ValueError(str(e))
try:
check_links(["http://eliot.readthedocs.io", "http://nosuchurl"])
except ValueError:
print("Not all links were valid.")
|