Sending an HTTP GET Request from a Python Script : HTTP Request « Network « Python Tutorial






import httplib

def printText(txt):
    lines = txt.split('\n')
    for line in lines:
        print line.strip()

httpServ = httplib.HTTPConnection("127.0.0.1", 80)
httpServ.connect()

httpServ.request('GET', "/test.html")

response = httpServ.getresponse()
if response.status == httplib.OK:
    print "Output from HTML request"
    printText (response.read())

httpServ.request('GET', '/cgi_form.cgi?name=Brad&quote=Testing.')

response = httpServ.getresponse()
if response.status == httplib.OK:
    print "Output from CGI request"
    printText (response.read())

httpServ.close()








21.19.HTTP Request
21.19.1.Sending an HTTP GET Request from a Python Script
21.19.2.Sending an HTTP POST Request from a Python Script
21.19.3.Obtain Web Page
21.19.4.Obtain Web Page With Full Error Handling
21.19.5.Obtain Web Page Information With Simple Error Handling
21.19.6.Obtain Web Page Information With Error Document Handling