urllib.error模块常用类有
1.urllib.error.URLError《处理URL程序异常》
例:
try:
result = urllib.request.urlopen("https://www.bilibili.com/404")
except urllib.error.URLError as e:
print(e.reason)
2.urllib.error.HTTPError 《处理http请求异常》
例:
try:
result = urllib.request.urlopen("https://www.bilibili.com/404")
except urllib.error.HTTPError as e:
print(e.reason,e.code,e.headers,sep="\n")
except urllib.error.URLError as e:
print(e.reason)
else:
print("request successfully")
网友评论