Skip to content
Snippets Groups Projects
Commit 419d4db5 authored by zero's avatar zero
Browse files

Upload New File

parent 8acf1c70
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id: tags:
``` python
"""
author: yc
date: 2022/10/20
"""
```
%% Cell type:code id: tags:
``` python
school_id = 169 # 南京大学(研究生)
student_id = '' # 学号
password = '123456'
```
%% Cell type:code id: tags:
``` python
import requests
import json
import re
import random
from time import sleep
```
%% Cell type:code id: tags:
``` python
referer = 'http://jy.anquanjy.com'
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36 Edg/105.0.1343.53'
s = requests.Session()
s.headers.update({
'User-Agent': user_agent,
'Referer': referer
})
with open('questions.json', 'r', encoding='utf-8') as f:
question_bank = json.load(f)
```
%% Cell type:code id: tags:
``` python
login_url = 'http://jy.anquanjy.com/inc/ajax/get/regLogin?isWeb=1&'
params = f'reg_school={school_id}&reg_xuehao={student_id}&reg_pass={password}'
r = s.get(login_url + params)
print(r.ok, r.json())
assert(int(r.json()['errCode']) == 0)
```
%% Cell type:code id: tags:
``` python
exam_info = {'isWeb':1, 'reg_from': 'PC端'}
r = s.get('http://jy.anquanjy.com/exam/ceshi')
assert(r.ok)
m = re.search(r'var school=\{([^}]+)\}', r.text)
t = m.group(1).strip().splitlines()
for line in t:
key = line.strip().split(':')[0]
m = re.findall(r'[0-9]+', line)
if len(m) == 0:
continue
value = m[-1]
exam_info[key] = value
get_exam_rul = 'http://jy.anquanjy.com/inc/ajax/get/getShijuan?'
params = '&'.join(f'{key}={value}' for key, value in exam_info.items())
r = s.get(get_exam_rul + params)
exam_info['kaoshiId'] = r.json()['data']['ID']
questions = r.json()['data']['list']
questions = json.loads(questions)
question_ids = [int(q['timu_id']) for q in questions]
answers = [(qid, question_bank[qid-1]['timu_daan']) for qid in question_ids]
blank_ans_cnt = random.randint(1, 3)
one_score_questions = [i for i in range(len(questions)) if float(questions[i]['timu_fen']) == 1]
for i in random.sample(one_score_questions, k=blank_ans_cnt):
answers[i] = (answers[i][0], '')
```
%% Cell type:code id: tags:
``` python
# 提交太快会被判定为非法
sleep(60)
```
%% Cell type:code id: tags:
``` python
# 如果被判非法,请重新执行该块
submit_url = 'http://jy.anquanjy.com/inc/ajax/save/saveKaoshi'
answers_str = ','.join([f'{qid}:{ans}' for qid, ans in answers])
submit_data = exam_info.copy()
# submit_data['reg_nowtime'] = int(exam_info['reg_nowtime']) + 30
submit_data['dati'] = answers_str
r = s.post(submit_url, submit_data)
print(r.json())
```
%% Cell type:code id: tags:
``` python
# 获取题库
# question_bank = []
# exercise_url = 'http://jy.anquanjy.com/inc/ajax/get/getLianxi?isWeb=1&'
# for i in tqdm(range(1, 21)):
# params = '&page_size=50&page={}&pagecount=20&listcount=0'.format(i)
# r = s.get(exercise_url + params)
# question_bank += r.json()['data']['list']
# with open('questions.json', 'w', encoding='utf-8') as f:
# json.dump(question_bank, f)
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment