[cookielib] How to add cookies myself?

Discussion in 'Python' started by Gilles Ganault, Dec 16, 2008.

  1. Hello

    I'm using urllib and urlib to download data from a web server that
    requires cookies.

    The issue I'm having, is the server uses JavaScript in the response to
    insert new cookies and send them with the next query, so I need to
    manually add a couple of cookies in the CookieJar, but I don't know
    how to do this and Google didn't return examples:

    =========
    import urllib
    import urllib2
    import cookielib

    headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows
    NT)' }
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)

    url = "http://www.acme.com/index.php"
    req = urllib2.Request(url, None, headers)
    response = urllib2.urlopen(req).read()

    print "Fetched cookies:"
    for index, cookie in enumerate(cj):
    print index, ' : ', cookie

    """
    How to Add manually?
    crm_cookieEnabled=1
    ctr=1
    """
    =========

    Thanks for any tip.
     
    Gilles Ganault, Dec 16, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C. Titus Brown

    RFC 2965 cookies, cookielib, and mailman.

    C. Titus Brown, Dec 27, 2004, in forum: Python
    Replies:
    0
    Views:
    514
    C. Titus Brown
    Dec 27, 2004
  2. John J Lee
    Replies:
    0
    Views:
    360
    John J Lee
    Jan 30, 2005
  3. Titus Brown
    Replies:
    0
    Views:
    483
    Titus Brown
    Feb 13, 2005
  4. Joshua Kugler
    Replies:
    2
    Views:
    873
    Joshua Kugler
    Dec 18, 2007
  5. _Who
    Replies:
    7
    Views:
    2,725
Loading...

Share This Page