惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
量子位
Recent Announcements
Recent Announcements
T
The Blog of Author Tim Ferriss
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Blog — PlanetScale
Blog — PlanetScale
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
V
Visual Studio Blog
博客园 - 聂微东
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog

Hi, I Am I

[I Am I 年度简报] — 不知终日梦为鱼 初探 ESP32-CAM QQ 聊天记录 MHT 文件转 HTML [I Am I 年度简报] - 草木本无意,荣枯自有时。 Hexo 中实现 Live Photos 支持 写在当下 NKCTF 2024 1z_F0r3ns1c5 Writeup 春秋杯冬季赛 2023 Writeup [I Am I 年度简报] - 2023 某内网渗透内部赛 Writeup 强网拟态 2023 Writeup Github Actions 自动化部署 Hexo 浅析CobaltStrike流量解密 陇剑杯 2023 Writeup CTF线下赛AWDP总结 ISCC 2023 Writeup ISCC 2023 实战题 Writeup CISCN 2023 Writeup 福建闽盾杯网络空间安全大赛 2023 Writeup 天一永安杯宁波市网络安全大赛 2023 Writeup 贵阳大数据及网络安全精英对抗赛 2023 Writeup 红明谷杯 2023 Writeup Confetti 带来有仪式感的鼓励 记一次 JS 逆向密码加密 [I Am I 年度简报] – 2022 PHP 读取 Excel 文件内容并写入数据库 从0开始的 MoeCTF 开发之路 观安杯 2022 Writeup 利用微信服务号实现早安自动化 Cloudflare批量拉黑IP脚本
Python 爬取学习通考试练习题目
2022-11-29 · via Hi, I Am I

起因:临近期末没有题库,只有学习通一个可以考 100次 的考试练习题,所以打算爬取下来看看题得了,毕竟学习通考试太浪费时间了。

1

点击 考试详情 复制网址,将必要参数 courseIdclassIdidCookie 填入代码即可

2

import re
import requests
from bs4 import BeautifulSoup

courseId = ''
classId = ''
id = ''
cookie = ''

url = 'http://mooc1.chaoxing.com/exam-ans/exam/test/reVersionPaperMarkContentNew?courseId=' + courseId + '&classId=' + classId + '&id=' + id
headers = {
    'Cookie' : cookie,
    'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36'
}
data = requests.get(url, headers=headers, verify=False).text

soup = BeautifulSoup(data, 'html.parser')

question_list = soup.find_all('div', class_='TiMu', style='position:relative')

for i in question_list:
    # 获取题目
    question = i.find('div', class_='fl clearfix').text
    # 获取题目选项
    try:
        option = i.find('ul', class_='Cy_ulTop').text
        option = re.sub(r'\s+', '', option)
        option = re.sub(r'([A-Z])', r'\n\1', option)
    except:
        option = ''
    # 获取题目答案
    answer = i.find('div', class_='Py_answer clearfix').text
    answer = re.sub(r'\s+', '', answer)
    answer = re.findall(r'正确答案:(.*?)我的答案', answer, re.S)[0]

    with open('list.txt', 'a', encoding='utf-8') as f:
        f.write("题目:" + question + '\n' + option + '\n' + "答案:" + answer + '\n' + '\n')

3