加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 20:07:51 所属栏目:Python 来源:网络整理
导读:复制代码 代码如下: 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.renre

复制代码 代码如下:

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()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读