Skip to content

Commit

Permalink
增加对于教师未完成测验情况的过滤与对题目未进行加密情况的处理 (#416)
Browse files Browse the repository at this point in the history
* 增加对于教师未完成测验情况的过滤

* 增加对题目未进行加密情况的处理
  • Loading branch information
wanqian-windrunner authored Jan 4, 2025
1 parent 5c87647 commit 5f95767
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,12 @@ def multi_cut(answer: str) -> list[str]:
},
)
_ORIGIN_HTML_CONTENT = _resp.text # 用于配合输出网页源码, 帮助修复#391错误

# 未创建完成该测验则不进行答题,目前遇到的情况是未创建完成等同于没题目
if '教师未创建完成该测验' in _resp.text:
logger.warning(f'教师未创建完成该测验')
return 0

questions = decode_questions_info(_resp.text) # 加载题目信息

# 搜题
Expand Down
23 changes: 17 additions & 6 deletions api/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,33 @@ def replace_rtn(text):
form_data = {}
form_tag = soup.find("form")

fd = FontDecoder(html_content) # 加载字体

# 抽取表单信息
for input_tag in form_tag.find_all("input"):
if "name" not in input_tag.attrs or "answer" in input_tag.attrs["name"]:
continue
form_data.update({input_tag.attrs["name"]: input_tag.attrs.get("value", "")})

form_data["questions"] = []

if soup.find("style", id="cxSecretStyle") is None: # 未找到字体文件,目前只有可能是空或者无中文内容。
logger.warning("未找到字体文件,可能是未加密的题目不进行解密")
else:
fd = FontDecoder(html_content) # 加载字体

for div_tag in form_tag.find_all(
"div", class_="singleQuesId"
): # 目前来说无论是单选还是多选的题class都是这个
q_title = replace_rtn(fd.decode(div_tag.find("div", class_="Zy_TItle").text))
q_options = ""
for li_tag in div_tag.find("ul").find_all("li"):
q_options += replace_rtn(fd.decode(li_tag.text)) + "\n"
if 'fd' in locals():
q_title = replace_rtn(fd.decode(div_tag.find("div", class_="Zy_TItle").text))
q_options = ""
for li_tag in div_tag.find("ul").find_all("li"):
q_options += replace_rtn(fd.decode(li_tag.text)) + "\n"
else:
q_title = replace_rtn(div_tag.find("div", class_="Zy_TItle").text)
q_options = ""
for li_tag in div_tag.find("ul").find_all("li"):
q_options += replace_rtn(li_tag.text) + "\n"
print(q_title,q_options)
q_options = q_options[:-1] # 去除尾部'\n'

# 尝试使用 data 属性来判断题型
Expand Down

0 comments on commit 5f95767

Please sign in to comment.