前言
把课后题爬下来当题库复习,不过考虑到我知识的熟练度和5天内复习完7门课的时间限制,选择手动把章节测验的网页源代码复制下来。别急昂,我们先忍他一手,考完试把它安排的明明白白
不想看原理的直接下拉到后面的百度云链接下载即可!
准备
1 2
| import os from bs4 import BeautifulSoup
|
核心代码
1 2 3 4
| workPath = 'e:/xxtDem/'
listFiles = os.listdir(workPath)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| for file in listFiles: currentFile = workPath + file with open(currentFile,mode='r',encoding='utf-8') as f: html = f.read()
soup = BeautifulSoup(html, 'lxml')
string = file + '\n' questions = soup.select('.TiMu')
for i in questions: question = i.select('div[style*="left"]') question = ''.join(question[0].text.split())
string += question + '\n' answers = i.select('form i, form p') length = len(answers) - 1 for index,j in enumerate(answers): if not j: break if index % 2 == 1: string += j.text + '\t' else: string += j.text if index == length: string += '\n'
string += '\n' with open('e:/demResult.txt',mode='a',encoding='utf-8') as f2: f2.write(string)
|
百度云链接
数字高程模型题库,提取码44d0!
结语
对于word的写入熟练度不高,并且部分题的配图没有进行解析,时间关系嘛!如果觉得下面的题库对你有用的话,麻烦赞赏扫码(狗头.jpg)!