how to remove specified cookie in cookie jar?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ken

    how to remove specified cookie in cookie jar?


    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.LWPCo okieJar()

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

  • John J. Lee

    #2
    Re: how to remove specified cookie in cookie jar?

    "ken" <ken.carlino@gm ail.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.LWPCo okieJar()
    >
    if cj is not None:
    if os.path.isfile( COOKIEFILE):
    print 'Loading Cookie--------------'
    cj.load(COOKIEF ILE)
    cj.clear('examp le.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_remove d(cookie):
    remove.append(c ookie)
    for cookie in remove:
    cj.clear(cookie .domain, cookie.path, cookie.name)




    """
    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

    Comment

    Working...