本帖最后由 Ne-21 于 2022-1-6 10:05 编辑
import requests
import random
import json
userInfo = {}
schoolList = []
answer = [
{'number': 66, 'answer': 'C'},
{'number': 329, 'answer': 'D'},
{'number': 466, 'answer': 'D'},
{'number': 171, 'answer': 'A'},
{'number': 414, 'answer': 'A'},
{'number': 242, 'answer': 'C'},
{'number': 422, 'answer': 'B'},
{'number': 529, 'answer': 'ABCD'},
{'number': 599, 'answer': 'ABC'},
{'number': 654, 'answer': 'ABCD'},
{'number': 694, 'answer': 'ABCD'},
{'number': 548, 'answer': 'CD'},
{'number': 553, 'answer': 'ABD'},
{'number': 1020, 'answer': 'B'},
{'number': 1046, 'answer': 'A'},
{'number': 880, 'answer': 'B'},
{'number': 1079, 'answer': 'B'},
{'number': 920, 'answer': 'A'},
{'number': 830, 'answer': 'B'},
{'number': 1049, 'answer': 'A'}
]
s = requests.Session()
headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,'
'application/signed-exchange;v=b3;q=0.9',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.34 '
}
def getSchoolList():
global schoolList
url = "https://haedu-2021.oss-cn-beijing.aliyuncs.com/gjaqzsjs/competition/unit.json"
res = s.get(url, headers=headers)
schoolList = res.json()
def getSchoolId(school):
if school == "":
return -1
for i in schoolList:
if i.get('char') == school:
return i.get('code')
else:
pass
return -1
def login(unit_code: int, student_id: str, password: str):
global userInfo
login_url = "http://gjaqzsjs.haedu.cn/Login/auth"
data = {
'unit_code': unit_code,
'student_id': student_id, # 12345678,
'password': password, # 12345678
}
res = s.post(login_url, data=data, headers=headers)
res = res.json()
if res.get('msg') != 'SUCCESS':
print(res.mag)
return False
else:
userInfo = res.get('data')
print('登录状态:', res.get('msg'))
print(userInfo)
return True
def getExamData():
global exam_paper_data
exam_url = 'http://gjaqzsjs.haedu.cn/Answer/getQuestionLists'
res = s.post(exam_url, headers=headers)
res = res.json()
if res.get('code') == 2000:
print('获取试卷成功')
exam_paper_data = res.get('data')
submit()
else:
print('获取试卷失败')
print(res)
def submit():
global answer
sub_url = 'http://gjaqzsjs.haedu.cn/Answer/submitAnswer'
data = {
'answer': json.dumps(answer),
'use_time': random.randint(500, 550)
}
res = s.post(sub_url, data=data, headers=headers)
print(res.json())
print("答案提交成功,请登录网页查看成绩!")
if __name__ == '__main__':
getSchoolList()
print("""
-------------欢迎使用安全知识竞赛助手,请使用账号密码登录。
---- 油猴中文网:https://bbs.tampermonkey.net.cn/?fromuser=Ne-21
---- 作者: Ne-21
---- 交流群:171221220
------------- 学习交流使用,请勿用于商业用途。
""")
while 1:
school = input('请输入学校名:')
unit_code = getSchoolId(school)
if unit_code == -1:
print("学校不存在,请重新输入!")
continue
else:
break
student_id = input("请输入登录账号:")
password = input("请输入登录密码:")
login(unit_code, student_id, password)
getExamData()
input("任意键退出")