python - 在 Python 中,如何使用 urllib 来查看一个网站是 404 还是 200?

标签 python urllib http-status-codes

如何通过urllib获取headers的代码?

最佳答案

getcode() 方法(在 python2.6 中添加)返回随响应发送的 HTTP 状态代码,如果 URL 不是 HTTP URL,则返回 None。

>>> a=urllib.urlopen('http://www.google.com/asdfsf')
>>> a.getcode()
404
>>> a=urllib.urlopen('http://www.google.com/')
>>> a.getcode()
200

关于python - 在 Python 中,如何使用 urllib 来查看一个网站是 404 还是 200?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1726402/

相关文章:

python - 使用 selenium python 发送 key 无效

python - urllib.request.Request 超时参数错误

python - urllib2:即使出现异常也可以获取 URL 内容

python - 使用 "tornado.httpclient"获取 "POST https"站点获取 "HTTPError: HTTP 599"

c# - 为多个 HttpStatusCodes 设置一个 ProducesResponseType typeof

http - 进行 Web 身份验证(HTTP 状态代码)的建议工作流程是什么?

validation - 返回 HTTP 409 是否适合验证检查?

python - 在 headless chrome 中等待带有元素的网页时出现超时异常

python - PyQt - 是否可以运行两个应用程序?

python - 串联字符串的字符串格式?