Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111142
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-05-24 17:21:18

 

# -*- coding: utf-8 -*-
import urllib
import urllib2
import cookielib

def login():
    #cookie
    cj=cookielib.LWPCookieJar()
    opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    
    #login information
    url='%3A%2F%2F%2FHome.do'
    email='test123@yahoo.com.cn'
    password='tttddd'
    
    headers={'Content-Type': 'application/x-www-form-urlencoded'}
    v_count={'email':email,'password':password,'submit':'登入'}
    data=urllib.urlencode(v_count)
    res=opener.open(url,data)
    
    print res.geturl() # 'Get the url after login, it can be used to check whether it login successfully or not.'
    
  
if __name__=='__main__':
    login()


The above programe used to login the renren site.

Here we use cookielib to create the cookie file. with the cookie, we can access the renren after login.

阅读(1136) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-07-22 21:43:24

lai a