What’s the best way to get an HTTP response code from a URL?

后端 未结 7 888
有刺的猬
有刺的猬 2020-11-28 02:34

I’m looking for a quick way to get an HTTP response code from a URL (i.e. 200, 404, etc). I’m not sure which library to use.

7条回答
  •  心在旅途
    2020-11-28 03:01

    In future, for those that use python3 and later, here's another code to find response code.

    import urllib.request
    
    def getResponseCode(url):
        conn = urllib.request.urlopen(url)
        return conn.getcode()
    

提交回复
热议问题