介绍

userid及考试项地址,即可自动考试。5分钟后自动提交~

操作
获取userid

登陆门户网站后点击学习平台,获取地址栏中的userid

获取考试科目页Url
生成文件

请将以下内容填写后写入到脚本目录下config_exam.json文件中

{
    "exam_url":
        "请填写考试科目页URL",
    "userid":
        "请通过F12进入控制台 Application 选项下 Cookies 获取LOGIN_USERID"
}
Python脚本
#中软在线考试答案获取 By:admin@ym68.cc
from __future__ import unicode_literals
import requests
import json
from urllib import parse
import six
import time
import easygui as mess
def ppt(obj, path='.', with_print=False, normal_path_print=False):
    base_string = str if six.PY3 else basestring
    obj = json.loads(obj) if isinstance(obj, base_string) else obj
    find_str, find_map = '', ['["%s"]', '[%s]', '%s', '.%s']
    for im in path.split('.'):
        if not im:
            continue
        if isinstance(obj, (list, tuple, base_string)):
            if im.startswith('[') and im.endswith(']'):
                im = im[1:-1]
            if ':' in im:
                slice_default = [0, len(obj), 1]
                obj, quota = obj[slice(
                    *[int(sli) if sli else slice_default[i] for i, sli in
                      enumerate(im.split(':'))])], 1
            else:
                obj, quota = obj[int(im)], 1
        else:
            if im in obj:
                obj, quota = obj[im], 0
            elif im.endswith('()'):
                obj, quota = list(getattr(obj, im[:-2])()), 3
            else:
                if im.isdigit():
                    obj, quota = obj[int(im)], 1
                else:
                    raise KeyError(im)
        find_str += find_map[quota] % im
    if with_print:
        print(obj if isinstance(obj, base_string) else
              json.dumps(obj,
                         indent=4,
                         sort_keys=True,
                         ensure_ascii=False))
    if normal_path_print:
        print('get it normally with: <obj>%s' % find_str)
    return obj
Auth_Mess = mess.enterbox(msg='请输入16位秘钥', title='安全验证', default='', strip=True, image=None, root=None)
if Auth_Mess != '520':
    quit("此脚本仅供测试参考,请勿用于非法用途!")
mess.msgbox(msg='此脚本仅供测试参考,请勿用于非法用途!',title='警告',ok_button='已知晓')
headers = {"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8","User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"}
#配置文件名
File_Name = "config_exam.json"
#读取文件内容
File_Code = open(File_Name,"r")
#将文件内容分成数组
Content = json.loads(File_Code.read())
Exam_Url = Content['exam_url']
#Exam_Url = mess.enterbox(msg='请输入考试科目页URL', title='URL获取', default='', strip=True, image=None, root=None)
#Exam_Url = input("此脚本仅供测试参考,请勿用于非法用途!\n请输入考试科目页URL:")
Exam_Url_Data = Exam_Url.split("&")
paper_id = Exam_Url_Data[1]
examid = Exam_Url_Data[6]
#通过Google Chrome F12查看Application下的Cookies LOGIN_USERID
userid = Content['userid']
#userid = mess.enterbox(msg='请输入获取到的UserID', title='Userid获取', default='', strip=True, image=None, root=None)
#获取题目列表
Exam_List_Url = "http://xa.chinasoftinc.com/lms/Bexamlist.do"
#userid = input("请在考试科目页通过F12查看Application下的Cookies LOGIN_USERID\n请输入userid:")
Exam_List_Data_1 = "action=examquelistbypaperid&examid="
Exam_List_Data_2 = "&userid="
Exam_List_Data_3 = "&paper_id="
Exam_List_Data_All = dict(action='examquelistbypaperid',examid=examid,userid=userid,paper_id=paper_id)
Exam_Code = requests.post(url=Exam_List_Url,data=Exam_List_Data_All,headers=headers)
Exam_Code_Text = Exam_Code.text
uniqId = str(ppt(Exam_Code_Text,'.uniqId'))
Exam_List_Code = ppt(Exam_Code_Text,'.ROOT')
Exam_List_B =  ""
for Exam_List_D in Exam_List_Code:
    Exam_List_A = str('{"QID":"%s","Qanswer":"","Type":"%s","Qother":""},'%(Exam_List_D['queQuestionId'],Exam_List_D['queType']))
    Exam_List_B+=Exam_List_A
Exam_List_C = parse.quote(Exam_List_B[:-1])
Exam_Post_Type_1 = 'action=queryScore&json=%5b'
Exam_Post_Type_2 = "%5d&paper_id="
Exam_Post_Type_3 = "&usetime=05%3A44%3A-20296&examid="
Exam_Post_Type_4 = "&uniqId="
#提交空答案
Exam_Post_Url = "http://xa.chinasoftinc.com/lms/Binput.do"
Exam_Post_Null_Data = Exam_Post_Type_1+Exam_List_C+Exam_Post_Type_2+paper_id+Exam_Post_Type_3+examid+Exam_Post_Type_4+uniqId

Exam_Post_Null_Code = requests.post(url=Exam_Post_Url,data=Exam_Post_Null_Data,headers=headers)
Exam_Code_Text = ppt(Exam_Post_Null_Code.text)
if Exam_Code_Text['score'] != float(0.0):
    print(Exam_Code_Text['score'])
    print(type(Exam_Code_Text['score']))
    mess.msgbox(msg='此脚本已失效!!', title='警告', ok_button='OK')
    quit()
#查看答案
Exam_Answer_Url = "http://xa.chinasoftinc.com/lms/Binput.do"
Exam_Answer_Type_1 = "action=queryResult&examid="
Exam_Answer_Type_2 = "&uniqId="
Exam_Answer_Data = Exam_Answer_Type_1+examid+Exam_Answer_Type_2+uniqId
Exam_Answer_Code = requests.post(url=Exam_Answer_Url,data=Exam_Answer_Data,headers=headers)
Exam_Answer_Code_D = Exam_Answer_Code.text
mess.msgbox(msg='将在5分钟后自动提交答案,请不要退出以免浪费考试机会!',title='提示',ok_button='已知晓')
#print("将在5分钟后自动提交答案,请不要退出以免浪费考试机会!")
time.sleep(300)
#提交答案
Exam_Answer_List = ppt(Exam_Answer_Code_D,'.root')
Exam_Answer_List_Code =  ""
for Exam_Answer_List_B in Exam_Answer_List:
    Exam_Answer_List_A = str('{"QID":"%s","Qanswer":"%s","Type":"%s","Qother":""},'%(Exam_Answer_List_B['questionID'],Exam_Answer_List_B['qanswer'],Exam_Answer_List_B['type']))
    Exam_Answer_List_Code+=Exam_Answer_List_A
Exam_Answer_List_C = parse.quote(Exam_Answer_List_Code[:-1])
Exam_Post_List_Data = Exam_Post_Type_1+Exam_Answer_List_C+Exam_Post_Type_2+paper_id+Exam_Post_Type_3+examid+Exam_Post_Type_4+uniqId
Exam_Post_Null_Code = requests.post(url=Exam_Post_Url,data=Exam_Post_List_Data,headers=headers)
Exam_Code_Text = ppt(Exam_Post_Null_Code.text)
#print("当前考试分数为: %s 考试已完成!" %Exam_Code_Text['score'])
mess.msgbox(msg='当前考试分数为: %s'%Exam_Code_Text['score'],title='提示',ok_button='好的')

该文章采用「CC 协议」,转载必须注明作者和本文链接.
分类: Python