file.getcode()网页状态码查询:
https://www.runoob.com/http/http-status-codes.html
简单模版
import urllib.request
import urllib.error
try:
data = urllib.request.urlopen('http://blog.youkuaiyun.com')
except urllib.error.URLError as err:
if hasattr(err,'code'):
print(err.code)
if hasattr(err,'reason'):
print(err.reason)

本文介绍如何使用Python的urllib库查询网页状态码,包括处理URLError异常,通过检查'code'和'reason'属性来判断HTTP请求的状态。
183

被折叠的 条评论
为什么被折叠?



