473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 6205
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: OldGuy | last post by:
Hi All Sendmail 8.12.11 php 4.3.9 Sendmail is installed and works properly. php is NOT in safemode from the command line; mail user@domain.com < testmsg works fine.
1
by: K. Byanjankar | last post by:
Hi, is there a way to remove item from cookie collection that has a key to it... -- Response.cookies("items")("item1") = "111111" Response.cookies("items")("item2") = "222222"...
12
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are...
3
by: Ram | last post by:
Hey, I'v got a group in ActiveDirectory that has about 2000 members. I want to remove a certain user from that group. When I tried to remove it using the group's DirectoryEntry:...
0
by: Soul | last post by:
Hi, I have a C# ASP.Net page allow users to enter their name and will set those value as cookie after click on "Submit" button. In addition, if user click on "Change" button, the cookie should...
6
by: Stephane | last post by:
Hi, I have a login page where if the user wants his access codes to be saved are set into a cookie. In the logout page, I want to delete those cookies. I tried this and this is not working at...
3
by: craigbennett | last post by:
Hi, I am trying to use std::remove to delete a file and have been encountering some problems. My goal is to pass std::remove a std::string and remove the file of that name, for example. ...
4
by: Jon Slaughter | last post by:
I have developed a technique to add and remove cookies after output... wondering if there is something else like this out there? Jon
3
by: webster5u | last post by:
Miss/Mr. Programmer, I have a idea to remove the cookie value from a website after all browser closed. It is like session kept in server and eliminate after all browser closed. My purpose is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.