修复登录错误
This commit is contained in:
parent
27222f6722
commit
478a2b041c
@ -56,7 +56,6 @@ def manageScheduleGet(request):
|
|||||||
else:
|
else:
|
||||||
return {'errcode': 400, 'errmsg': '数据校验失败'}
|
return {'errcode': 400, 'errmsg': '数据校验失败'}
|
||||||
|
|
||||||
|
|
||||||
# 工具函数
|
# 工具函数
|
||||||
|
|
||||||
# MD5 校验
|
# MD5 校验
|
||||||
|
32
lib/cache.py
Normal file
32
lib/cache.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import json
|
||||||
|
import requests
|
||||||
|
from urllib.parse import quote
|
||||||
|
import base64
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import random
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# JSON转base64
|
||||||
|
def btoa(content):
|
||||||
|
return base64.b64encode(quote(content).encode())
|
||||||
|
|
||||||
|
s = requests.Session()
|
||||||
|
|
||||||
|
params = {
|
||||||
|
'Dto': {
|
||||||
|
'Code': "",
|
||||||
|
'LoginName': "2017002372",
|
||||||
|
'PassWord': "102710",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
params = str(btoa(json.dumps(params)))[2:-1]
|
||||||
|
|
||||||
|
url = 'https://jwgl.cust.edu.cn/api/LoginApi/LocalLogin'
|
||||||
|
|
||||||
|
params = {
|
||||||
|
"__log":{"Logtype":1},
|
||||||
|
"param": params
|
||||||
|
}
|
||||||
|
|
||||||
|
r = s.post(url=url, data=params)
|
||||||
|
print(r.text)
|
@ -25,7 +25,7 @@ class Crawler(object):
|
|||||||
self.__session = requests.Session()
|
self.__session = requests.Session()
|
||||||
# 获取统一身份系统的网页
|
# 获取统一身份系统的网页
|
||||||
r = self.__session.get(
|
r = self.__session.get(
|
||||||
url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1')
|
url='https://mysso.cust.edu.cn/cas/login?service=https://jwgls1.cust.edu.cn/welcome')
|
||||||
soup = BeautifulSoup(r.text, 'html.parser')
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
execution = soup.find_all(name='input')[6]['value']
|
execution = soup.find_all(name='input')[6]['value']
|
||||||
formdata = {
|
formdata = {
|
||||||
@ -36,7 +36,7 @@ class Crawler(object):
|
|||||||
'geolocation': ''
|
'geolocation': ''
|
||||||
}
|
}
|
||||||
r = self.__session.post(
|
r = self.__session.post(
|
||||||
url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1', data=formdata)
|
url='https://mysso.cust.edu.cn/cas/login?service=https://jwgls1.cust.edu.cn/welcome', data=formdata)
|
||||||
soup = BeautifulSoup(r.text, 'html.parser')
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
flag = soup.find(name='title')
|
flag = soup.find(name='title')
|
||||||
if(flag.text == "手机号设置"):
|
if(flag.text == "手机号设置"):
|
||||||
@ -50,25 +50,24 @@ class Crawler(object):
|
|||||||
'submit': '提交'
|
'submit': '提交'
|
||||||
}
|
}
|
||||||
r = self.__session.post(
|
r = self.__session.post(
|
||||||
url="http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=https%3A%2F%2Fwebvpn.cust.edu.cn%2Fauth%2Fcas_validate%3Fentry_id%3D1", data=formdata)
|
url="https://mysso.cust.edu.cn/cas/login?service=https://jwgls1.cust.edu.cn/welcome", data=formdata)
|
||||||
r = self.__session.get(
|
r = self.__session.get(
|
||||||
url='http://portal-cust-edu-cn-s.webvpn.cust.edu.cn:8118/custp/index')
|
url='https://portal.cust.edu.cn/custp/index')
|
||||||
soup = BeautifulSoup(r.text, 'html.parser')
|
soup = BeautifulSoup(r.text, 'html.parser')
|
||||||
try:
|
try:
|
||||||
self.__ip = soup.findAll(name='a')[7]['href'][7:].split("-")
|
if soup.findAll(name='a')[4]['href'] != 'logout':
|
||||||
|
raise('账号或密码错误')
|
||||||
except:
|
except:
|
||||||
return ('账号或者密码错误', 510)
|
return ('账号或者密码错误', 510)
|
||||||
r = self.__session.get(url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=http://' +
|
self.__ip = ['jwgls0', 'cust', 'edu', 'cn']
|
||||||
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome', allow_redirects=False)
|
r = self.__session.get(url='https://mysso.cust.edu.cn/cas/login?service=https://jwgls1.cust.edu.cn/welcome', allow_redirects=False)
|
||||||
ticket = r.headers['Location'][72:]
|
ticket = r.headers['Location'][42:]
|
||||||
asp_net_sessionid_param = {'Ticket': ticket, 'Url': 'http://' +
|
asp_net_sessionid_param = {'Ticket': ticket, 'Url': 'https://jwgls1.cust.edu.cn/welcome'}
|
||||||
self.__ip[0] + '.' + self.__ip[1] + '.' + self.__ip[2] + '.' + self.__ip[3] + ':8080/welcome'}
|
|
||||||
asp_net_sessionid_param = base64.b64encode(
|
asp_net_sessionid_param = base64.b64encode(
|
||||||
quote(json.dumps(asp_net_sessionid_param)).encode('utf-8')).decode('utf-8')
|
quote(json.dumps(asp_net_sessionid_param)).encode('utf-8')).decode('utf-8')
|
||||||
asp_net_sessionid_param = {'param': asp_net_sessionid_param}
|
asp_net_sessionid_param = {'param': asp_net_sessionid_param}
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
r = self.__session.post(url='http://' + self.__ip[0] + '-' + self.__ip[1] + '-' + self.__ip[2] + '-' + self.__ip[3] +
|
r = self.__session.post(url='https://jwgls1.cust.edu.cn/api/LoginApi/LGSSOLocalLogin?sf_request_type=ajax', data=json.dumps(asp_net_sessionid_param), headers=headers)
|
||||||
'-8080-p.webvpn.cust.edu.cn:8118/api/LoginApi/LGSSOLocalLogin?sf_request_type=ajax', data=json.dumps(asp_net_sessionid_param), headers=headers)
|
|
||||||
data = json.loads(r.content.decode('utf-8'))
|
data = json.loads(r.content.decode('utf-8'))
|
||||||
# 提示未建立教务信息
|
# 提示未建立教务信息
|
||||||
if data['state'] == 1:
|
if data['state'] == 1:
|
||||||
@ -80,12 +79,11 @@ class Crawler(object):
|
|||||||
print(e)
|
print(e)
|
||||||
return ('教务挂了', 512)
|
return ('教务挂了', 512)
|
||||||
|
|
||||||
# 获取课表 -----------------------------------------------------------------------------
|
# 获取成绩 -----------------------------------------------------------------------------
|
||||||
def getGrade(self):
|
def getGrade(self):
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
r = self.__session.post(
|
r = self.__session.post(
|
||||||
url='http://' + self.__ip[0] + '-' + self.__ip[1] + '-' + self.__ip[2] + '-' + self.__ip[3] +
|
url='https://jwgls1.cust.edu.cn/api/ClientStudent/QueryService/GradeQueryApi/GetDataByStudent?sf_request_type=ajax',
|
||||||
'-8080-p.webvpn.cust.edu.cn:8118/api/ClientStudent/QueryService/GradeQueryApi/GetDataByStudent?sf_request_type=ajax',
|
|
||||||
data=json.dumps({"param": "JTdCJTIyU2hvd0dyYWRlVHlwZSUyMiUzQTElN0Q=", "__permission": {"MenuID": "4443798E-EB6E-4D88-BFBD-BB0A76FF6BD5",
|
data=json.dumps({"param": "JTdCJTIyU2hvd0dyYWRlVHlwZSUyMiUzQTElN0Q=", "__permission": {"MenuID": "4443798E-EB6E-4D88-BFBD-BB0A76FF6BD5",
|
||||||
"Operation": 0}, "__log": {"MenuID": "4443798E-EB6E-4D88-BFBD-BB0A76FF6BD5", "Logtype": 6, "Context": "查询"}}),
|
"Operation": 0}, "__log": {"MenuID": "4443798E-EB6E-4D88-BFBD-BB0A76FF6BD5", "Logtype": 6, "Context": "查询"}}),
|
||||||
headers=headers
|
headers=headers
|
||||||
@ -233,20 +231,18 @@ class Crawler(object):
|
|||||||
}
|
}
|
||||||
return ('ok', 200)
|
return ('ok', 200)
|
||||||
|
|
||||||
# 获取成绩 -----------------------------------------------------------------------------
|
# 获取课表 -----------------------------------------------------------------------------
|
||||||
def getSchedule(self):
|
def getSchedule(self):
|
||||||
headers = {'Content-Type': 'application/json'}
|
headers = {'Content-Type': 'application/json'}
|
||||||
r = self.__session.post(
|
r = self.__session.post(
|
||||||
url='http://'+self.__ip[0]+'-'+self.__ip[1]+'-'+self.__ip[2]+'-'+self.__ip[3] +
|
url='https://jwgls1.cust.edu.cn/api/ClientStudent/Home/StudentHomeApi/GetHomeCurWeekTime?sf_request_type=ajax',
|
||||||
'-8080-p.webvpn.cust.edu.cn:8118/api/ClientStudent/Home/StudentHomeApi/GetHomeCurWeekTime?sf_request_type=ajax',
|
|
||||||
data=json.dumps({"param": "JTdCJTdE", "__permission": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E",
|
data=json.dumps({"param": "JTdCJTdE", "__permission": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E",
|
||||||
"Operation": 0}, "__log": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E", "Logtype": 6, "Context": "查询"}}),
|
"Operation": 0}, "__log": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E", "Logtype": 6, "Context": "查询"}}),
|
||||||
headers=headers
|
headers=headers
|
||||||
)
|
)
|
||||||
CurWeek = json.loads(r.content.decode('utf-8'))['data']['CurWeek']
|
CurWeek = json.loads(r.content.decode('utf-8'))['data']['CurWeek']
|
||||||
r = self.__session.post(
|
r = self.__session.post(
|
||||||
url='http://'+self.__ip[0]+'-'+self.__ip[1]+'-'+self.__ip[2]+'-'+self.__ip[3] +
|
url='https://jwgls1.cust.edu.cn/api/ClientStudent/Home/StudentHomeApi/QueryStudentScheduleData?sf_request_type=ajax',
|
||||||
'-8080-p.webvpn.cust.edu.cn:8118/api/ClientStudent/Home/StudentHomeApi/QueryStudentScheduleData?sf_request_type=ajax',
|
|
||||||
data=json.dumps({"param": "JTdCJTdE", "__permission": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E",
|
data=json.dumps({"param": "JTdCJTdE", "__permission": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E",
|
||||||
"Operation": 0}, "__log": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E", "Logtype": 6, "Context": "查询"}}),
|
"Operation": 0}, "__log": {"MenuID": "F71C97D5-D3E2-4FDA-9209-D7FA8626390E", "Logtype": 6, "Context": "查询"}}),
|
||||||
headers=headers
|
headers=headers
|
||||||
|
@ -8,18 +8,18 @@ class TestCrawler(unittest.TestCase):
|
|||||||
def test_connection(self):
|
def test_connection(self):
|
||||||
self.assertEqual(c.connection(), ('ok', 200))
|
self.assertEqual(c.connection(), ('ok', 200))
|
||||||
|
|
||||||
# 测试获取成绩
|
#测试获取成绩
|
||||||
# def test_grade(self):
|
def test_grade(self):
|
||||||
# self.assertEqual(c.getGrade(), ('ok', 200))
|
self.assertEqual(c.getGrade(), ('ok', 200))
|
||||||
|
|
||||||
# 测试获取课表
|
#测试获取课表
|
||||||
# def test_schedule(self):
|
def test_schedule(self):
|
||||||
# self.assertEqual(c.getSchedule(), ('ok', 200))
|
self.assertEqual(c.getSchedule(), ('ok', 200))
|
||||||
|
|
||||||
# 测试返回信息
|
#测试返回信息
|
||||||
# def test_getData(self):
|
def test_getData(self):
|
||||||
# get_res = c.getData()
|
get_res = c.getData()
|
||||||
# self.assertEqual(get_res['errcode'], '200')
|
self.assertEqual(get_res[1], 200)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
@ -2,8 +2,8 @@ from pymongo import MongoClient
|
|||||||
from bson import ObjectId, json_util
|
from bson import ObjectId, json_util
|
||||||
|
|
||||||
# 主环境 (生产环境为production,开发环境为development)
|
# 主环境 (生产环境为production,开发环境为development)
|
||||||
setting = 'development'
|
setting = 'production'
|
||||||
env = 'coc'
|
env = 'ali'
|
||||||
|
|
||||||
# 获取数据集
|
# 获取数据集
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ def col(arg):
|
|||||||
def addRank(nick, count, time):
|
def addRank(nick, count, time):
|
||||||
try:
|
try:
|
||||||
col('rank').update({"cid": cid}, {'$setOnInsert': {"nick": nick}, '$set': {
|
col('rank').update({"cid": cid}, {'$setOnInsert': {"nick": nick}, '$set': {
|
||||||
"count": count, "time": time}}, {'upsert': 'true'})
|
"count": count, "time": time}} , {'upsert': 'true'})
|
||||||
# col('rank').insert_one({"count":count,"time":time,"nick":nick})
|
# col('rank').insert_one({"count":count,"time":time,"nick":nick})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# 失败
|
# 失败
|
||||||
@ -37,8 +37,6 @@ def addRank(nick, count, time):
|
|||||||
return {'errcode': 200, 'errmsg': 'ok'}
|
return {'errcode': 200, 'errmsg': 'ok'}
|
||||||
|
|
||||||
# 获取排名表所有信息(除了id)
|
# 获取排名表所有信息(除了id)
|
||||||
|
|
||||||
|
|
||||||
def getRank():
|
def getRank():
|
||||||
time_rank = []
|
time_rank = []
|
||||||
count_rank = []
|
count_rank = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user