1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
import requests import re
class vRuc: url_token = 'https://uc.tiup.cn/account/login?client_id=uc.tiup.cn&redirect_uri=%2Foauth%2Fauthorize%3Fclient_id%3Duc.tiup.cn%26redirect_uri%3Dhttp%253A%252F%252Fv.ruc.edu.cn%252Fsso%252Flogin%253Fredirect_uri%253D%25252FUser%2526school_code%253Druc%2526theme%253Dschools%26response_type%3Dcode%26school_code%3Druc%26scope%3Dall%26sso%3Dtrue%26state%3DZ08-C1r99RVtBwYVkEm12XxfhvVlW680YDKwfAaPU1DG-_mx%26theme%3Dschools&response_type=code&school_code=ruc&scope=all&sso=true&state=Z08-C1r99RVtBwYVkEm12XxfhvVlW680YDKwfAaPU1DG-_mx&theme=schools' url_login = 'https://uc.tiup.cn/account/login' url_redirect ='https://uc.tiup.cn/oauth/authorize?client_id=uc.tiup.cn&redirect_uri=http%3A%2F%2Fv.ruc.edu.cn%2Fsso%2Flogin%3Fredirect_uri%3D%252FUser%26school_code%3Druc%26theme%3Dschools&response_type=code&school_code=ruc&scope=all&sso=true&state=vhfL6zHS_J4cH88Z_A-ZHl7RIUxmPrZEnffvYdtsCf7tWpz7&theme=schools' url_score = 'http://app.ruc.edu.cn/idc/education/report/xscjreport/XscjReportAction.do?method=printXscjReport&xh=' url_myCourse='http://app.ruc.edu.cn/idc/education/selectcourses/studentselectcourse/StudentSelectCourseAction.do' s = requests.Session() myheader={ 'Referer': 'http://app.ruc.edu.cn/idc/education/report/xscjreport/XscjReportAction.do?method=queryXscjReport', 'User-Agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36', 'Accept-Encoding':'gzip, deflate, sdch', 'Accept-Language':'zh-CN,zh;q=0.8,en;q=0.6', } def startLogin(self,username,password): self.login(self.getToken(),username,password) self.redirect() def getScore(self): r = self.s.get(self.url_score,headers=self.myheader) r.encoding='gbk' print r.text def redirect(self): self.s.get(self.url_redirect) def login(self,csrf_token,username,password): postData = { 'csrf_token' : csrf_token, 'school_code' : 'ruc', 'username': username, 'password': password, 'remember_me' : 'true' } self.s.post(self.url_login,data=postData) def getToken(self): r = self.s.get(self.url_token) csrf_token=r.cookies['csrf_token'] return csrf_token def getMyCourse(self): postData = { 'method': 'queryXkjg', 'isNeedInitSQL': 'true', 'xnd' :'2014-2015', 'xq': '2', 'condition_xnd': '2014-2015', 'condition_xq': '2', 'condition_kclb':'', 'condition_spbz': '' } r = self.s.post(self.url_myCourse,data=postData,headers=self.myheader) r.encoding='gbk' print r.text
ruc = vRuc()
username='' password='' ruc.startLogin(username, password) ruc.getMyCourse()
|