urllib 中的异常处理
import urllib.request
import urllib.parse
import urllib.error
#异常错误捕获
url = 'https://www.ahvndkmvl.net'
try:
response = urllib.request.urlopen(url)
print(response)
except urllib.error.HTTPError as e:
print(e)
print(e.code)
except urllib.error.URLError as e:
print(e)