欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-11-02 19:58:58
复制代码 代码如下:import reimport urllib2import cookielib def renren():    cj...

复制代码 代码如下:

import re
import urllib2
import 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)id="currentstatus">.*?<a ui-async="async" title="([^"]*)'
    match = re.search(s, res, re.dotall)
    if match:
        result = match.groups(1)
        print 'current status: ', result[0]

renren()