Skip to content

Instantly share code, notes, and snippets.

@azizmb azizmb/test_urls.py
Created Jan 2, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.