python实现人人网登录示例分享

代码如下:

import reimport urllib2import cookielib

def renren(): cj = cookielib.lwpcookiejar() opener = urllib2.build_opener(urllib2.httpcookieprocessor(cj)) email = ” pwd = ” #登录.. print ‘login……’ url = “http://www.renren.com/plogin.do” postdata = “email=”+email+”&password=”+pwd+”&origurl=http%3a%2f%2fwww.renren.com%2fsyshome.do&domain=renren.com” req = urllib2.request(url,postdata) res = opener.open(req).read() print ‘succeed!’ #得到当前状态 s = r'(?s)>.*? match = re.search(s, res, re.dotall) if match: result = match.groups(1) print ‘current status: ‘, result[0]

renren()

发表评论