cookielib

S

sri2097

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...nal&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 ?
 
R

Rene Pijlman

sri2097:
urllib2 does not support cookies.

It does in 2.4. This code enables cookie support in all consequent calls
through urrlib2:

import cookielib, urllib2
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top