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.

Revisions

  1. sandgate-dev created this gist Mar 9, 2019.
    11 changes: 11 additions & 0 deletions check_url_exists.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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."