[Tutor] Cookies

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Fri Apr 9 15:39:41 EDT 2004

On Thu, 8 Apr 2004, Scott wrote:

> Hi all.  Is there a way to get the value of a particular cookie for a
> particular website that has been left behind by a web-browser?
> Hopefully, this would work whether the user has Mozilla or IE or Opera,
> etc.  Thanks.

Hi Scott,

Hmmm... I believe that cookies are stored on by the browser itself, so if
you have access to the cookie file that lives on the browser, it should be
possible to eat that.

The Mozilla browser, for example, keeps a 'cookies.txt' file, and it looks
something like this:

[dyoo at tesuque 987rqvz4.slt]$ head cookies.txt
# HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
# To delete cookies, use the Cookie Manager.

ads.specificpop.com	FALSE		FALSE	1609459199	id
ads.specificpop.com	FALSE		FALSE	1609459199	fci
www.baxter2.com	FALSE		FALSE	1092257148	lang	english
www.linuxjournal.com	FALSE		FALSE	1092862778	lang
.specificpop.com	TRUE		FALSE	1609459199	cpa

Hmmm... so it should be possible to parse this file, since it's
tab-delimited.  Ah!  Someone has written a parser for cookie files in the
Python Cookbook:


Ok, so that step is done.  *grin*

I did some more Googling, and according to:


the cookies for IE lives in a 'Cookies' subdirectory, but that
subdirectory is in several possible places, depending on what version of
Windows you're running.

Thankfully, there's also an entry in the Cookbook to grab IE cookie files
without having to worry about that detail:


I can't test this since I don't have Windows available at the moment.
Can anyone confirm that it has the same structure as the Mozilla cookie

So all the pieces are almost there.  I don't think anyone has yet worked
on writing a nice set of functions to uniformly grab cookie files for all
the different browsers, though.  If one did exist, I'd expect it in
'webbrowser', so perhaps it might be worthwhile to try adding some
functionality in 'webbrowser' to do this.

Talk to you later!

More information about the Tutor mailing list