#!/usr/bin/env python import httplib import urllib from urlparse import urlparse # Set infile, outfile inPath = "urls.txt" outPath = "headers.csv" # Open the infile and process infile = open(inPath, 'rU') if infile: outfile = open(outPath, 'w') outfile.write("URL,HEADER,MESSAGE\n") for line in infile: parsed_url = urlparse(line) grab = httplib.HTTP(parsed_url[1]) grab.putrequest('GET', parsed_url[2]) grab.endheaders() errcode, errmsg, header = grab.getreply() domain = parsed_url[1] path = parsed_url[2] url = domain + path print "URL: %s" % url outfile.write("%s,%s,%s\n" % (url, errcode, errmsg)) # Close the files infile.close() outfile.close() else: print "Error opening the infile"