You could try to do this with getcode() from urllib
getcode()
import urllib.requestprint(urllib.request.urlopen("https://www.stackoverflow.com").getcode())
200
For Python 2, use
print urllib.urlopen("http://www.stackoverflow.com").getcode()
I think the easiest way to do it is by using Requests module.
import requestsdef url_ok(url): r = requests.head(url) return r.status_code == 200
You can use httplib
import httplibconn = httplib.HTTPConnection("www.python.org")conn.request("HEAD", "/")r1 = conn.getresponse()print r1.status, r1.reason
prints
200 OK
Of course, only if www.python.org is up.
www.python.org