Last active
December 14, 2015 21:18
-
-
Save vincenting/5149836 to your computer and use it in GitHub Desktop.
从华师信息门户获得当前登录用户姓名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import urllib2, urllib, re, cookielib | |
def CCNUAuth(su_id=None, su_psw=None): | |
""" | |
根据学号和密码获取姓名,失败返回false | |
:param su_id: | |
:param su_psw: | |
:return: | |
""" | |
if not (su_id and su_psw): | |
return False | |
cookie = cookielib.CookieJar() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) | |
opener.addheaders = [('Connection', 'Keep-Alive')] | |
opener.addheaders = [('Cache-Control', 'no-cache')] | |
url_login = "http://portal.ccnu.edu.cn/loginAction.do" | |
body = (('userName', su_id), ('userPass', su_psw)) | |
if len(opener.open(url_login, urllib.urlencode(body)).read()) != 53: | |
return False | |
auth_result = opener.open('http://portal.ccnu.edu.cn/index_jg.jsp').read() | |
return re.compile("(.*?) ").findall(auth_result)[1].decode('gb2312').replace(' ', '') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment