#!/usr/bin/python # download a web page to standard output # Usage: httpdn.py [http://]url import httplib, string, sys import mimetools, rfc822 # parse argument: url= sys.argv[1] if url[:7]== 'http://' : url= url[7:] ix= string.find(url, '/') if ix>= 0: host= url[:ix] file= url[ix:] # include the preceding slash else : host= url file= '/index.html' print "Host: "+ host+ " File: "+ file # here we go: hc= httplib.HTTPConnection(host) hc.request("GET", file) hr= hc.getresponse() if hr.status>= 300 and hr.status<= 399: # redirect file= hr.getheader('Location') if file[-1] != '/': file= file+ '/index.html' hc.request("GET", file) hr= hc.getresponse() data= hr.read() hc.close() print data