python coockie,request another page

Posted by polovinamozga on Stack Overflow See other posts from Stack Overflow or by polovinamozga
Published on 2010-06-06T10:17:16Z Indexed on 2010/06/06 10:22 UTC
Read the original article Hit count: 431

Filed under:
|
|
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import httplib
import Cookie
import cookielib

Login = 'user'
Password = 'password'
Domain = 'inbox.ru'
Auth = 'https://auth.mail.ru/cgi-bin/auth'


cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'Login' : Login,
                               'Domain' :Domain,  
                               'Password' : Password
                               })

opener.open('https://auth.mail.ru/cgi-bin/auth', login_data)
resp = opener.open('https://auth.mail.ru/cgi-bin/auth').read()
print resp.decode('cp1251') #output page in cp1251

When script sucessfully executed i see in print resp.decode('cp1251') my page with auth. But when a try to request another page for example http://my.mail.ru i see autorization request.

How i can use cookie with another page?

© Stack Overflow or respective owner

Related posts about python

Related posts about request