How can I get the content of a web site using http library

kyosohma at gmail.com kyosohma at gmail.com
Thu Mar 29 15:34:06 EDT 2007


On Mar 29, 2:18 pm, "silverburgh.me... at gmail.com"
<silverburgh.me... at gmail.com> wrote:
> I am trying to get the content of a web site like this:
> But my question is how can I do a 'GET' request without putting the '/
> index.html''
>
>    h = httplib.HTTP('www.yahoo.com')
>
>         # it takes 2 arguments here, but I don't know if the site has
> '/index.html' , how can I leave this out?
>
>         h.putrequest('GET')
>         h.endheaders()
>
>         errcode, errmsg, headers = h.getreply()
>
>         if (errcode == 200):
>
>             f = h.getfile()
>
> Thank you for your help.

You may want to go with the urllib module instead. Check out the how-
to below:

http://www.voidspace.org.uk/python/articles/urllib2.shtml

Mike




More information about the Python-list mailing list