-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetans.py
More file actions
25 lines (22 loc) · 759 Bytes
/
Copy pathgetans.py
File metadata and controls
25 lines (22 loc) · 759 Bytes
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
import requests as r
import re
def getans(url):
'''
et-blank 填空题
et-tof 判断题
et-blank block 长填空题
et-choice 选择题
'''
res = r.get(url)
# \xc3\xa9 = é, > = >, we need to escape them
txt = res.text.encode('latin-1').decode('utf-8').replace('>', '>').replace('capitolize', 'capitalize')
pat = [r'<et-blank(?: capitalize)?>(.*?)</et-blank>',
r'<et-tof key="(\w)">',
r'<et-blank block>(.*?)</et-blank>',
r'<et-choice key="(\w)">']
pattern = [re.compile(i, re.S) for i in pat]
answer = [re.findall(i, txt) for i in pattern]
special = '</et-mobile-only>'
if special in txt:
answer = [i[:len(i)//2] for i in answer]
return answer, txt