[cookielib] How to add cookies myself?

G

Gilles Ganault

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top