#!/usr/bin/python # extract CGI forms from a web page to standard output # in a simplified form suitable for customizing # Usage: httpdn.py [http://]url import httplib, re, string, sys # 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() html= hr.read() hc.close() print '' print '
' # beheader the HTML: ix= string.find(html, '') if ix< 0: ix= string.find(html, '') if ix< 0: # there's no head head= '' body= html else : head= html[:ix+7] body= html[ix+7:] # get what we want from the head: ix =string.find(head, '