cookielib

sri2097 srikar2097 at gmail.com
Wed Feb 22 04:54:52 EST 2006


Hi, I need to get to a particular page in a website. The site uses
cookeis and naturally I had to use cookielib since urllib2 does not
support cookies. But even after adding the cookies to the headers, I
keep getting a error message from the web-site saying that - 'My
Browser has disabled cookies and I cannot access the page'. Here is the
code I wrote -

cookie_obj = cookielib.CookieJar()

# First page
socket = urllib2.Request("http://www.zap2it.com/index")
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data

# Second page
socket =
urllib2.Request("http://tvlistings2.zap2it.com/index.asp?partner_id=national&mash=mash1&zipcode=01810&submit1=Continue")
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data

# Third Page
socket =
urllib2.Request("http://tvlistings2.zap2it.com/system.asp?partner_id=national&zipcode=01810")
cookie_obj.add_cookie_header(socket)
data = urllib2.urlopen(socket).read()
print data


Is there anything wrong in the above done code. I printed out the all
the HTML headers in each stage to see if the cookie is getting added or
not. I found out that the cookies are not getting added. But when I do
"socket.info().headers" I get a list of all the headers wherein I can
see 'Set-Cookie' tag and the cookie value.

Anyone got any suggestions ?




More information about the Python-list mailing list