Please try like below. Hopefully you will get some idea.
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
list_of_website = ['http://www.google.com/','https://paste.ubuntu.com/','http://algotoolz.com/']
for website in list_of_website:
req = Request(website)
try:
response = urlopen(req)
except HTTPError as e:
print('The server couldn't fulfill the request.')
print('Error code: ', e.code)
except URLError as e:
print('We failed to reach a server.')
print('Reason: ', e.reason)
else:
print ('Website is working fine')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…