Created
August 2, 2014 17:05
-
-
Save jhorneman/a14e49c3a9fc8a31a257 to your computer and use it in GitHub Desktop.
Small script to check for dead links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def check_link(_url): | |
_url = _url.strip() | |
if not _url: | |
return | |
if not _url.startswith('http://'): | |
_url = 'http://' + _url | |
try: | |
r = requests.get(_url) | |
except requests.ConnectionError: | |
print "Connection Error", _url | |
else: | |
if r.status_code != 200: | |
print r.status_code, _url | |
if __name__ == "__main__": | |
for line in open("links.txt"): | |
check_link(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment