remove bs4
This commit is contained in:
21
main.py
21
main.py
@ -13,7 +13,6 @@ from typing import Callable, List, Optional
|
|||||||
import dotenv
|
import dotenv
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from serverchan_sdk import sc_send as _sc_send
|
from serverchan_sdk import sc_send as _sc_send
|
||||||
|
|
||||||
# 配置日志
|
# 配置日志
|
||||||
@ -206,11 +205,23 @@ class Lessons:
|
|||||||
)
|
)
|
||||||
res.raise_for_status()
|
res.raise_for_status()
|
||||||
html = res.text
|
html = res.text
|
||||||
bs = BeautifulSoup(html, "html.parser")
|
# 使用正则表达式替代 BeautifulSoup 来查找选中的学期选项
|
||||||
match = bs.select_one("select#jhxn option[selected]")
|
# 由于 HTML 结构特殊,selected 在单独行上,需要向前查找对应的 option
|
||||||
if not match:
|
lines = html.split('\n')
|
||||||
|
for i, line in enumerate(lines):
|
||||||
|
if 'selected' in line.strip():
|
||||||
|
# 向前查找包含 option value 的行
|
||||||
|
for j in range(i-1, max(0, i-10), -1):
|
||||||
|
if 'option value=' in lines[j]:
|
||||||
|
value_match = re.search(r'value="([^"]*)"', lines[j])
|
||||||
|
if value_match:
|
||||||
|
self.term = str(value_match.group(1))
|
||||||
|
break
|
||||||
|
if self.term:
|
||||||
|
break
|
||||||
|
|
||||||
|
if not self.term:
|
||||||
raise LessonsException("未找到学期信息")
|
raise LessonsException("未找到学期信息")
|
||||||
self.term = str(match.get("value"))
|
|
||||||
|
|
||||||
print(self.fajhh, self.term)
|
print(self.fajhh, self.term)
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
python-dotenv
|
python-dotenv
|
||||||
pandas
|
pandas
|
||||||
requests
|
requests
|
||||||
beautifulsoup4
|
|
||||||
serverchan-sdk
|
serverchan-sdk
|
||||||
openpyxl
|
openpyxl
|
Reference in New Issue
Block a user