Python - urllib2 & cookielib

Posted by Adrian on Stack Overflow See other posts from Stack Overflow or by Adrian
Published on 2011-01-03T08:15:48Z Indexed on 2011/01/04 0:54 UTC
Read the original article Hit count: 387

Filed under:
|
|

I am trying to open the following website and retrieve the initial cookie and use it for the second url-open BUT if you run the following code it outputs 2 different cookies. How do I use the initial cookie for the second url-open?

import cookielib, urllib2

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

home = opener.open('https://www.idcourts.us/repository/start.do')
print cj

search = opener.open('https://www.idcourts.us/repository/partySearch.do')
print cj

Output shows 2 different cookies every time as you can see:

<cookielib.CookieJar[<Cookie JSESSIONID=0DEEE8331DE7D0DFDC22E860E065085F for www.idcourts.us/repository>]>
<cookielib.CookieJar[<Cookie JSESSIONID=E01C2BE8323632A32DA467F8A9B22A51 for www.idcourts.us/repository>]>

© Stack Overflow or respective owner

Related posts about python

Related posts about urllib2