[Tutor] urllib2 and cookies

SwartMumba snake swartmumba at yahoo.com
Thu Oct 25 08:59:28 CEST 2007


I want to read the html source off a site but the site requires cookies. What code must I use to handle my cookies, instead of me typing them out? NB I want to use urllib2 to open the site, not urllib. I am currently using python 2.5

This is what I have done so far, but I do not want to type out all the cookies.

import urllib2
data = urllib2.Request(url = "http://www.example.com", data = 'COOKIE:<xx;xx...>')
htmlSource = urllib2.urlopen(data).read()

Thanks in advance...

 __________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071024/30fd6d8a/attachment.htm 


More information about the Tutor mailing list