Created
September 6, 2015 03:30
-
-
Save zfz/045d9b62740308e6cfc6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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