又到期末考试了,需要做问卷星来复习了。
但是网络教学平台上的题太多了,没办法写了个脚本来提取。
通过此脚本生成的excel,可以直接导入问卷星生成问卷。

1. 使用步骤

  1. 登录网络教学平台
  2. F12 打开开发者工具->Application->cookie

  1. 找到 JSESSIONID 这个字段,把他的值复制下来。然后把代码中的JSEESIONID替换成你的
s = requests.get(url, headers={'cookie': 'JSESSIONID=2820553AF02867CBE9DB35273D032158'# 这里=后面的替换成你的sessionid
})
  1. 安装 pandas, requests, BeautifulSoup依赖
pip install beautifulsoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple
  1. 复制你要爬取的测试结果页面(注意是结果页面!!就是已经答完,可以查看答案的那种结果页面)的URL网址,把测试名也带上去
fetch_all([
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=84246354', '第二章测试题'),
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=85256551', '第三章测试题'),
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91007573', '第五章测试'),
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91008411', '第六章测试'),
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91251387', '第七章测试'),
('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91318025', '8237和DAC0832测试'),
])

2. 完整代码

import timeimport pandas as pd
import requests
from bs4 import BeautifulSoupdef right_answer_convert(option_list: list):index_list = [i for i, item in enumerate(option_list) if '答案' in item]answer_tag_text = option_list[index_list[0]]for _ in index_list:option_list.remove(answer_tag_text)ret_answer = []for i, item in enumerate(index_list):ret_answer.append(chr(ord('A') + item - i - 1))return ''.join(ret_answer)def fetch_one(url, save_file=''):s = requests.get(url, headers={'cookie': 'JSESSIONID=D916E34E743A99701B33AC73CDE3F6ED','User-Agent':'Mozilla/5.0(iPhone;U;CPUiPhoneOS4_3_3likeMacOSX;en-us)AppleWebKit/533.17.9(KHTML,likeGecko)Version/5.0.2Mobile/8J2Safari/6533.18.5'})soup = BeautifulSoup(s.text, 'html.parser')question_raw_list = soup.find_all('div', class_='test_checkq_question_editorWrapper')ret_list = []for question_raw in question_raw_list:each_question = dict()each_question['type'] = '单选'each_question['title'] = question_raw.find('div', class_='title').text.strip()question_option = question_raw.find('div', class_='item')# print(question_option)if question_option is None:each_question['answer'] = question_raw.find('div', class_='rightAnswer_body').text.strip()print(each_question['answer'])if each_question['answer'] in ['T', 'F']:each_question['type'] = '判断题'each_question['answer'] = each_question['answer'].replace('T', '对').replace('F', '错')each_question['option'] = ['对', '错']else:each_question['type'] = '简答题'else:question_option = question_raw.find('div', class_='item').find_all('span')each_question['option'] = list(map(lambda x: x.get_text(), question_option))each_question['answer'] = right_answer_convert(each_question['option'])each_question['option'] = list(filter(lambda x: '答案' not in x, each_question['option']))each_question['type'] = '单选题' if len(each_question['answer']) == 1 else '多选题'ret_list.append(each_question)col_name_list = ['题型', '题目', '选项1', '选项2', '选项3', '选项4', '选项5', '正确答案', '答案解析', '分值']df = pd.DataFrame(columns=col_name_list)for i in ret_list:template = {'题型': i['type'],'题目': i['title'],'正确答案': i['answer'],'答案解析': '','分值': '1'}if i['type'] not in ['判断题', '简答题']:for j, item in enumerate(i['option']):template['选项' + str(j + 1)] = item# df = df.append(template, ignore_index=True)df = pd.concat([df, pd.DataFrame(template, index=[0])], ignore_index=True)timestamp = str(int(time.mktime(time.localtime(time.time()))))df.to_excel('{}_{}.xlsx'.format(save_file, timestamp), index=False)# print(df)def fetch_all(url_list):for i in url_list:fetch_one(i[0], i[1])if __name__ == '__main__':fetch_all([('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=84246354', '第二章测试题'),('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=85256551', '第三章测试题'),('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91007573', '第五章测试'),('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91008411', '第六章测试'),('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91251387', '第七章测试'),('https://eplat.imau.edu.cn/meol/test/stuQtestResult.do?testId=91318025', '8237和DAC0832测试'),])

Python+BeautifulSoup实现网络教学平台学生测试题导出相关推荐

  1. springboot大学生网络教学平台的设计与实现毕业设计源码281819

    目  录 摘要 1 绪论 1.1研究背景及意义 1.2研究现状 1.3系统开发技术的特色 1.4论文结构与章节安排 2大学生网络教学平台系统分析 2.1 可行性分析 2.2 系统流程分析 2.2.1数 ...

  2. 大学生网络教学平台的设计与实现 毕业设计-附源码281819

    目  录 摘要 1 绪论 1.1研究背景及意义 1.2研究现状 1.3系统开发技术的特色 1.4论文结构与章节安排 2大学生网络教学平台系统分析 2.1 可行性分析 2.2 系统流程分析 2.2.1数 ...

  3. python+vue+elementui大学生网络教学平台

    管理员管理模块 (1)用户管理:管理员可以对前台上注册过的学生用户信息以及教师用户进行管控,也可以对管理员信息进行管控. (2)系统内容:管理员可以对大学生网络教学平台前台展示的课程交流.论坛分类.校 ...

  4. 校园版网络教学平台搭建方案(学生端)

    随着在线教育的发展,很多学校也开始考虑接入内网完善网络教学平台搭建方案,为的就是能够避免由于类似疫情这种情况所造成不能到校上课的情况,接下来小编将会提供一套完整的针对于学生端的内网网络教学平台搭建方案 ...

  5. 基于php的网络教学平台,基于PHP技术的网络教学平台的设计与实现

    崔静静+++项小书+++吴燕红 摘要:该文基于简易.灵活的PHP语言及Sql Server数据库技术,设计并实现网络教学平台.该平台重点实现了在线测试.在线答疑等功能,为课堂教学提供了有益补充,增强了 ...

  6. 河南科技大学c语言网络教学平台,计算机基础教学部

    主任 薛冰冰 副教授 副主任 俞卫华 计算机基础教学部隶属于河南科技大学电子信息工程学院,承担着全校各个专业的计算机公共基础课的教学任务.计算机基础教学部经历了30年的发展,先后开设过<BASI ...

  7. python机器视觉教材_基于Python的机器视觉实验教学平台设计

    基于 Python 的机器视觉实验教学平台设计 韩志豪 ; 刘晓英 [期刊名称] <计算机测量与控制> [年 ( 卷 ), 期] 2020(028)003 [摘要] 针对机器视觉领域的学习 ...

  8. 基于jsp(java)网络教学平台系统的设计与实现

    欢迎添加微信互相交流学习哦! 项目源码:https://gitee.com/oklongmm/biye2 摘 要 远程教育作为现代教育技术的形式,给教育思想与技术带来了革命性的变革,己经成为现代教育的 ...

  9. 基于jsp(java)网络教学平台系统的设计和开发(含源文件)

    获取项目源文件,联系Q:1225467431,可指导毕设,课设 摘 要 远程教育作为现代教育技术的形式,给教育思想与技术带来了革命性的变革,己经成为现代教育的必然要求.远程教育要得以顺利.高效的实施, ...

最新文章

  1. 深拷贝与浅拷贝~动态内存释放有关
  2. Seamless cloning泊松克隆
  3. 生活中人人都是主角,也都不是主角
  4. 免费下载 | 全景揭秘阿里文娱智能算法
  5. .NET Core 如何生成信用卡卡号
  6. 开源的类似于Apache ab的压力测试命令行工具SuperBenchmarker
  7. Error running ‘xxx‘: Command line is too long. Shorten command line for xxx or also for Spring Boot
  8. Callable 和 Future接口 学习
  9. 实验一 DOS命令解释程序的编写
  10. ERROR: Failed to Setup IP tables: Unable to enable SKIP DNAT rule
  11. pymongo基本方法使用笔记
  12. Unity 移动 和 旋转 [小结]
  13. 什么是三层交换机-三层交换机的工作原理和作用
  14. 2021年化工自动化控制仪表考试资料及化工自动化控制仪表免费试题
  15. xiaoxin juju needs help - 组合公式
  16. Vue 扫码及生成二维码
  17. 最简单DIY基于51单片机的舵机控制器
  18. SpringMVC常用方法大全
  19. C++中二维数组的动态创建于处理(zzl
  20. mysql迭代器_迭代器是什么,C++ STL迭代器(iterator)用法详解

热门文章

  1. 猹猹查叉叉『查找专题』
  2. 让文本可以直接粘贴到Excel中,并分列分行
  3. 论文翻译1-----DSSM:Deep Structured Semantic Models
  4. 视频转二维码怎么操作?简单一步在线生成视频二维码
  5. python 迭代器详解
  6. 删除SQL表数据时存在约束的解决方法
  7. RAID 阵列碎片整理真的管用!碎片整理对于RAID仍然有意义
  8. 【使用ChatGPT制作PPT】
  9. 【瑕疵检测】基于matlab GUI Gabor滤波布匹瑕疵检测【含Matlab源码 407期】
  10. python画椭圆形函数算法_python如何使用matplotlib绘制椭圆的数学公式-百度经验