Skip to content

Instantly share code, notes, and snippets.

@jeffgodwyll
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffgodwyll/5b180b956ed8080466de to your computer and use it in GitHub Desktop.
Save jeffgodwyll/5b180b956ed8080466de to your computer and use it in GitHub Desktop.
Test for valid url before scraping
import requests
def url_exists(url):
response = requests.get(url)
return response.status_code == requests.codes.ok
url_exists('http://google.com') #True: exists
url_exists('http://jeffgodwyll.com/ht.m') #False: doesn't exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment