469,931 Members | 2,734 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,931 developers. It's quick & easy.

how to remove specified cookie in cookie jar?

ken

How to remove specified cookie (via a given name) in cookie jar?

I have the following code, but how can I remove a specified cookie in
the cookie jar?
cj = cookielib.LWPCookieJar()

if cj is not None:
if os.path.isfile(COOKIEFILE):
print 'Loading Cookie--------------'
cj.load(COOKIEFILE)

Mar 31 '07 #1
1 5579
"ken" <ke*********@gmail.comwrites:
How to remove specified cookie (via a given name) in cookie jar?

I have the following code, but how can I remove a specified cookie in
the cookie jar?
cj = cookielib.LWPCookieJar()

if cj is not None:
if os.path.isfile(COOKIEFILE):
print 'Loading Cookie--------------'
cj.load(COOKIEFILE)
cj.clear('example.com', '/', 'cookiename')
Note that the domain arg must match the cookie domain exactly (and the
domain might, for example, start with a dot). You may want to iterate
over the Cookie objects in the CookieJar to find the one(s) you want
to remove, but it's not supported to remove them at the same time as
iterating, so (UNTESTED):

remove = []
for cookie in cj:
if is_to_be_removed(cookie):
remove.append(cookie)
for cookie in remove:
cj.clear(cookie.domain, cookie.path, cookie.name)
http://docs.python.org/lib/cookie-jar-objects.html

"""
clear( [domain[, path[, name]]])
Clear some cookies.

If invoked without arguments, clear all cookies. If given a single
argument, only cookies belonging to that domain will be
removed. If given two arguments, cookies belonging to the
specified domain and URL path are removed. If given three
arguments, then the cookie with the specified domain, path and
name is removed.

Raises KeyError if no matching cookie exists.
"""
John
Apr 1 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by K. Byanjankar | last post: by
12 posts views Thread by Sam Collett | last post: by
3 posts views Thread by Ram | last post: by
reply views Thread by Soul | last post: by
6 posts views Thread by Stephane | last post: by
3 posts views Thread by craigbennett | last post: by
4 posts views Thread by Jon Slaughter | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.