2024年的普法考试又开始了,昨天晚上花了点时间把题库和答案爬了一下,好像不太全,不过考了几个都在90分以上[Python] 纯文本查看 复制代码 import requests
import json
from pprint import pprint
headers = {
'User-Agent': 'Mozilla/5.0 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36)',
'Referer':'https://exam.gxpf.cn',
'Connection':'keep-alive',
'cookies':'你的cookie',
'a-code':'-86141162',
'a-st':'时间戳',
'a-tokenid':'你的tokenid',
'a-userid':'你的userid'
}
url = 'https://exam.gxpf.cn/exercise.html?time=时间戳'
response = requests.get(url, headers=headers)
print(response)
urllist = 'https://exam.gxpf.cn/examapi/rest/api/exercise/getRandomExerciseLocalList'
responsep = requests.post(urllist, headers=headers,params={'position':'1','offset':'5000'})
print(responsep)
jsondata = json.loads(responsep.text)
pprint(jsondata)
# 创建一个列表来保存处理后的题目数据
processed_data = []
# 初始化题目序号
question_number = 1
# 创建一个集合来保存已经出现过的题目
seen_questions = set()
# 遍历result中的所有题目
for subject in jsondata['result'][0]['list']:
subject_type = subject['subjectType']
subject_name = subject['subject_name']
detail = subject['detail']
# 初始化一个列表来保存所有isResult为1的题目的itemQuestion
item_questions_with_result = []
# 遍历detail列表,提取每个题目的itemQuestion,如果isResult为1
for item in detail:
if item.get('isResult') == 1:
item_questions_with_result.append(item.get('itemQuestion'))
# 创建一个唯一的题目表示(这里假设题目内容是唯一的)
unique_question_representation = (subject_type, subject_name, tuple(item_questions_with_result))
# 检查题目是否已经出现过
if unique_question_representation not in seen_questions:
# 将题目类型、题目以及答案保存到列表中,并添加序号
processed_data.append({
"序号": question_number,
"题目类型": subject_type,
"题库题目": subject_name,
"正确答案": item_questions_with_result
})
# 打印题目类型、题目以及答案,并包含序号
print(f'序号:{question_number}')
print(f'题目类型:{subject_type}')
print(f'题库题目:{subject_name}')
print(f'正确答案:{item_questions_with_result}')
print('====================')
# 更新题目序号和已见题目集合
question_number += 1
seen_questions.add(unique_question_representation)
# 指定要保存的文件名
filename = 'processed_questions_and_answers.json'
# 将处理后的数据写入JSON文件
with open(filename, 'w', encoding='utf-8') as file:
json.dump(processed_data, file, ensure_ascii=False, indent=4)
# 输出文件名
print(f"数据已保存到 {filename}")
爬出来的题库和答案
processed_questions_and_answers.txt
(1.48 MB, 下载次数: 171, 售价: 2 CB吾爱币)
|