urllib & cookies
carlos eberhardt
carlos.eberhardt at techrepublic.com
Thu May 17 12:00:03 EDT 2001
I think you need to use httplib instead. One of the first things (explains
any foolishness that might be pointed out - this was a sloppy bit to prove
to a colleague that the idea should work - at least, i think this code will
work) I did in Python was to retrieve a URL that required a cookie:
import httplib
host = 'www.yourhost.com'
page = '/url/to/retrieve.html'
cookietext = 'contents-of-cookie-here'
h = httplib.HTTP(host)
h.putrequest('GET', page)
h.putheader('host', host)
h.putheader('user-agent', 'python-httplib')
h.putheader('Accept', 'text/html')
h.putheader('Accept', 'text/plain')
h.putheader('Cookie', cookietext)
h.endheaders()
errcode, errmsg, headers = h.getreply()
print errcode, errmsg
if errcode == 200:
f = h.getfile()
data = f.readlines()
f.close()
data contains the results.
(maybe?)
carlos
"Miki Tebeka" <tebeka at lycosmail.com> wrote in message
news:9e0jsq$kb1 at news.or.intel.com...
> Hello All,
>
> Can someone direct me to an example of using urllib and Cookie.
>
> I have a site I want to access, this site requires a cookie (I have it in
> the IE cookies directory).
> How to I do it?
>
> Thanks.
More information about the Python-list
mailing list