我正在尝试使用以下代码在 python 中检索 URL 列表的 HTTP 状态代码:
try:
r = requests.head(testpoint_url)
print(testpoint_url+" : "+str(r.status_code))
# prints the int of the status code.
except requests.ConnectionError:
print("failed to connect")
令人惊讶的是,对于某些 URL,我得到302状态代码,而如果通过浏览器浏览,您会看到它显示 404 代码!
到底是怎么回事?我怎样才能获得真正的状态代码(例如 404)?
相关分类