SV: getting a URL

Max Møller Rasmussen maxm at normik.dk
Fri Jun 9 03:24:59 EDT 2000


Fra: johnvert at my-deja.com [mailto:johnvert at my-deja.com]

Here's a small snippet i sometimes use.

it's not to safe though as there's no exception handling

########################################################

def HTTPGet(URL, page):
    h = httplib.HTTP(URL)
    h.putrequest('GET', page)
    h.putheader('Accept', 'text/html')
    h.putheader('Accept', 'text/plain')
    h.endheaders()
    errcode, errmsg, headers = h.getreply()
    #print errcode # Should be 200
    f = h.getfile()
    data = f.read() # Get the raw HTML
    f.close()
    return data

htmlPage = HTTPGet('www.python.org', '/doc/current/lib/module-urllib.html')

#####################################################

urllib is probably even simpler.




More information about the Python-list mailing list