Skip to content

Instantly share code, notes, and snippets.

@sandgate-dev
Created March 9, 2019 10:23
Show Gist options
  • Save sandgate-dev/4d67662ae933e3539322e06b40903c1c to your computer and use it in GitHub Desktop.
Save sandgate-dev/4d67662ae933e3539322e06b40903c1c to your computer and use it in GitHub Desktop.
# How can I determine if anything at the given url exists
# https://stackoverflow.com/a/1966141/5983691
#
# 4xx status codes describe client errors (like "404 Not found")
# 5xx status codes describe server errors (like "500 Internal server error")
from urllib2 import urlopen
code = urlopen("http://example.com/").code
if (code / 100 >= 4):
print "Nothing there."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment