Skip to content

Instantly share code, notes, and snippets.

@azizmb
Created January 2, 2013 13:45
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 azizmb/4434680 to your computer and use it in GitHub Desktop.
Save azizmb/4434680 to your computer and use it in GitHub Desktop.
Script to test the status for a bunch of urls, with aggregate counts in the end. Usage: python test_urls.py file_with_404_links.txt
import sys
from collections import defaultdict
import requests
file_name = sys.argv[1]
results = defaultdict(list)
with open(file_name) as f:
for url in f:
r = requests.get(url, allow_redirects=False)
results[r.status_code].append(url)
print "%d - %s" % (r.status_code, url)
print "========================"
for status, urls in results.items():
print "%d - %d" % (status, len(urls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment