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