[Tutor] urllib2 and cookies

Kent Johnson kent37 at tds.net
Thu Oct 25 13:01:36 CEST 2007


Michael Meier wrote:
> Hi
> 
> ASPN has a very verbose example of cookielib usage at
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302930

There is a writeup of this recipe here:
http://www.voidspace.org.uk/python/articles/cookielib.shtml

This is way more complicated than you need, though, at least if you are 
using Python 2.4 or 2.5 you can just use cookielib. The first example 
here shows how simple it can be:
http://docs.python.org/lib/cookielib-examples.html

Note that you may have to open two pages with the same urlopener - the 
page that sets the cookie (perhaps a login page?) and the page that 
requires the cookie.

Kent


More information about the Tutor mailing list