Skip to content

Instantly share code, notes, and snippets.

@zfz
Created September 6, 2015 03:30
Show Gist options
  • Save zfz/045d9b62740308e6cfc6 to your computer and use it in GitHub Desktop.
Save zfz/045d9b62740308e6cfc6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
#-*-coding: utf-8 -*-
import urllib2
import sys
def load_url(f):
return [line.strip() for line in open(f)]
def query_url(l):
for url in l:
request = urllib2.Request(url)
request.get_method = lambda : 'HEAD'
try:
response = urllib2.urlopen(request, timeout=5)
if response.info().gettype() == 'text/html':
print "{0},{1}".format(url, 'GOOD')
else:
print "{0},{1}".format(url, 'BAD')
except:
print "{0},{1}".format(url, 'BAD')
if __name__ == '__main__':
f = sys.argv[1]
l = load_url(f)
query_url(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment