正如题名
目标:江苏省职校生安全教育学习平台
语言:Python
ide:VCod
最后使用时间为2021.01.09,不保证以后考试规则及网站代码不变,若尝试此教程不通根据抓包到的API进行脚本编写即可
思路:登录考试平台后手动在线模拟考试,观察考试规则,发现其规则是选择某题目确定答案选择下一题会时时判断上题目是否正确,也就是常见的边考边系统时时审核答案。既然是系统自动审核那一定有固定的题目及答案的API接口,我们只要抓包答案API即可
实际动手过程中考试平台必须看满8小时学习视频才能参与考试,模拟考试和正式考试是不一样的(正式考试可以多次考,取其中最高分数)在抓包的过程,发现模拟考试和正式考试的题目API是分开的并且,模拟考试题目API包含正确答案,正式考试题目API只有题目,具体json参数如下:
#模拟考试API
{code: 1,…}
code: 1
quesInfo: [{questionId: "cqmsah2sxbxj0z2nbgdhq", questionType: 1, Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。",…}]
0: {questionId: "cqmsah2sxbxj0z2nbgdhq", questionType: 1, Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。",…}
Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。"
analysis: ""
answers: ["3"]
0: "3"
questionId: "cqmsah2sxbxj0z2nbgdhq"
questionType: 1
selects: ["自行拆修", "丢弃", "不管不顾", "及时报修"]
0: "自行拆修"
1: "丢弃"
2: "不管不顾"
3: "及时报修"
stuAnswers: []
# 正式考试API
{code: 1,…}
code: 1
quesInfo: [{questionId: "cqmsah2sxbxj0z2nbgdhq", questionType: 1, Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。",…}]
0: {questionId: "cqmsah2sxbxj0z2nbgdhq", questionType: 1, Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。",…}
Content: "定期检查宿舍内的水管、电源、电器,发现故障应该( )。"
analysis: ""
answers: [""]
0: "null"
questionId: "cqmsah2sxbxj0z2nbgdhq"
questionType: 1
selects: ["自行拆修", "丢弃", "不管不顾", "及时报修"]
0: "自行拆修"
1: "丢弃"
2: "不管不顾"
3: "及时报修"
stuAnswers: []
一开始以为正式考试的题目答案顺序跟模拟考试一样,实际题目的答案全部打乱随机的。
最终还是懒没高兴做一键自动考试的脚本(考题有100个怕做出来搞使用者看乱了)
根据模拟考试题目API和正式考试规则写了根据题目ID查答案并提示考题类型(判断题、多选题、单选题)
使用教程:打开正式考题的API接口,复制考题IDquestionId
粘贴进程序里查询即可
具体实现代码如下:
import requests
import json
url_SecTiKu = 'https://aq.fhmooc.com/api/portal/PaperStuByQuesType/getModuleQuesList' # 安全教育题库API接口
timu_api = 'https://aq.fhmooc.com/api/portal/PaperStuByQuesType/getQuestionInfo' # 获取模拟考试题目ID API接口
# 获取正式考试题目API接口 参数courseId=qkcfawcsxyrom0zrwghhwq
kaoshi_url = "https://aq.fhmooc.com/api/design/PaperStudent/getStuPaper"
# Cookie通过登录的时候页面属性查看login的链接即可找到
header = {"Cookie": ''}
def jiangsu():
print("**************************\n")
key = input('请输入题目ID:')
#获取题目及答案
timu_data = {"courseId": '', "quesId": key}
timu_html = requests.post(timu_api, headers=header, data=timu_data)
# print(timu_html.json())
timu_json = timu_html.json()
timu_json = timu_json["quesInfo"][0]
# print(timu_json)
timu_json_id = timu_json["questionId"]
timu_json_questionType = timu_json["questionType"]
timu_json_title = timu_json["Content"]
timu_json_selects = timu_json["selects"]
timu_json_answers = timu_json["answers"]
timu_answers = timu_json_answers[0]
timu_daan = int(timu_answers)
# 判断题目类型
if timu_json_questionType == 1:
print("题目类型:单选题" + "\n题目ID:" + timu_json_id + "\n标题:" +
timu_json_title + "\n答案:" + timu_json_selects[timu_daan])
elif timu_json_questionType == 2:
print("题目类型:多选题" + "\n题目ID:" + timu_json_id +
"\n标题:" + timu_json_title + "\n答案:")
for i in timu_json_answers:
# print(timu_json_answerss[i])
i = int(i)
print(i, timu_json_selects[i])
elif timu_json_questionType == 3:
if timu_daan == 0:
print("题目类型:判断题" + "\n题目ID:" + timu_json_id +
"\n标题:" + timu_json_title + "\n答案:" + "错误")
else:
print("题目类型:判断题" + "\n题目ID:" + timu_json_id +
"\n标题:" + timu_json_title + "\n答案:" + "正确")
else:
print("获取题型失败")
while True:
jiangsu()