Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
2
2022江苏大学生安全知识竞赛 一键通过
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ethan Lu
2022江苏大学生安全知识竞赛 一键通过
Commits
419d4db5
Commit
419d4db5
authored
2 years ago
by
zero
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
8acf1c70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.ipynb
+178
-0
178 additions, 0 deletions
main.ipynb
with
178 additions
and
0 deletions
main.ipynb
0 → 100644
+
178
−
0
View file @
419d4db5
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
"author: yc\n",
"date: 2022/10/20\n",
"\"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"school_id = 169 # 南京大学(研究生)\n",
"student_id = '' # 学号\n",
"password = '123456'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json\n",
"import re\n",
"import random\n",
"from time import sleep"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"referer = 'http://jy.anquanjy.com'\n",
"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'\n",
"s = requests.Session()\n",
"s.headers.update({\n",
" 'User-Agent': user_agent,\n",
" 'Referer': referer\n",
"})\n",
"\n",
"with open('questions.json', 'r', encoding='utf-8') as f:\n",
" question_bank = json.load(f)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"login_url = 'http://jy.anquanjy.com/inc/ajax/get/regLogin?isWeb=1&'\n",
"params = f'reg_school={school_id}®_xuehao={student_id}®_pass={password}'\n",
"r = s.get(login_url + params)\n",
"print(r.ok, r.json())\n",
"assert(int(r.json()['errCode']) == 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"exam_info = {'isWeb':1, 'reg_from': 'PC端'}\n",
"r = s.get('http://jy.anquanjy.com/exam/ceshi')\n",
"assert(r.ok)\n",
"m = re.search(r'var school=\\{([^}]+)\\}', r.text)\n",
"t = m.group(1).strip().splitlines()\n",
"for line in t:\n",
" key = line.strip().split(':')[0]\n",
" m = re.findall(r'[0-9]+', line)\n",
" if len(m) == 0:\n",
" continue\n",
" value = m[-1]\n",
" exam_info[key] = value\n",
"\n",
"get_exam_rul = 'http://jy.anquanjy.com/inc/ajax/get/getShijuan?'\n",
"params = '&'.join(f'{key}={value}' for key, value in exam_info.items())\n",
"r = s.get(get_exam_rul + params)\n",
"exam_info['kaoshiId'] = r.json()['data']['ID']\n",
"\n",
"questions = r.json()['data']['list']\n",
"questions = json.loads(questions)\n",
"question_ids = [int(q['timu_id']) for q in questions]\n",
"answers = [(qid, question_bank[qid-1]['timu_daan']) for qid in question_ids]\n",
"\n",
"blank_ans_cnt = random.randint(1, 3)\n",
"one_score_questions = [i for i in range(len(questions)) if float(questions[i]['timu_fen']) == 1]\n",
"for i in random.sample(one_score_questions, k=blank_ans_cnt):\n",
" answers[i] = (answers[i][0], '')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 提交太快会被判定为非法\n",
"sleep(60)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 如果被判非法,请重新执行该块\n",
"submit_url = 'http://jy.anquanjy.com/inc/ajax/save/saveKaoshi'\n",
"answers_str = ','.join([f'{qid}:{ans}' for qid, ans in answers])\n",
"submit_data = exam_info.copy()\n",
"# submit_data['reg_nowtime'] = int(exam_info['reg_nowtime']) + 30\n",
"submit_data['dati'] = answers_str\n",
"r = s.post(submit_url, submit_data)\n",
"print(r.json())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# 获取题库\n",
"\n",
"# question_bank = []\n",
"# exercise_url = 'http://jy.anquanjy.com/inc/ajax/get/getLianxi?isWeb=1&'\n",
"# for i in tqdm(range(1, 21)):\n",
"# params = '&page_size=50&page={}&pagecount=20&listcount=0'.format(i)\n",
"# r = s.get(exercise_url + params)\n",
"# question_bank += r.json()['data']['list']\n",
"\n",
"# with open('questions.json', 'w', encoding='utf-8') as f:\n",
"# json.dump(question_bank, f)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.7 64-bit",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.7"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "650239b40d57889207069651a25b5f4398de4e8f6ad94d5be669e3968afbfcd9"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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
}
®_xuehao=
{
student_id
}
®_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)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment