How to view the body of HTTP page?
Robert W. Bill
rbill at digisprings.com
Tue Aug 1 23:05:24 EDT 2000
On Wed, 2 Aug 2000, Sam Wun wrote:
> I found no method is suitable in HTTP object for retrieving the document
> body from http webpage.
> Does anyone know any way of doing that?
>
> Thanks
> Sam.
the getfile() method is what you are looking for. This method
returns a file object that you can read from.
The example below is roughly the same as what is in the Python
Library Reference (11.3):
>>>import httplib
>>>h = httplib.HTTP("www.python.org")
>>>h.putrequest('GET', '/')
>>>h.putheader('Accept', 'text/html')
>>>h.endheaders()
>>>responsecode, responsemessage, headers = h.getreply()
>>>print errcode # should be 200
- here's the part you're looking for -
>>>f = h.getfile()
>>>documentBody = f.read() # here's the data you're seeking
>>>f.close()
>>>print documentBody
Visit http://www.python.org/doc/current/lib/lib.html for
inspiration.
-robert
More information about the Python-list
mailing list