首頁  >  文章  >  後端開發  >  python实现人人网登录示例分享

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

WBOY
WBOY原創
2016-06-16 08:45:341003瀏覽

复制代码 代码如下:

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">.*?    match = re.search(s, res, re.DOTALL)
    if match:
        result = match.groups(1)
        print 'current status: ', result[0]

renren()

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn