Skip to content

Commit

Permalink
修复二级目录课程列表无法识别
Browse files Browse the repository at this point in the history
  • Loading branch information
41369ly authored and Samueli924 committed Dec 20, 2023
1 parent 92b4096 commit c32b360
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
19 changes: 17 additions & 2 deletions api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from api.config import GlobalConst as gc
from api.decode import (decode_course_list,
decode_course_point,
decode_course_card)
decode_course_card,
decode_course_folder)


def get_timestamp():
Expand Down Expand Up @@ -92,7 +93,21 @@ def get_course_list(self):
_resp = _session.post(_url, data=_data)
# logger.trace(f"原始课程列表内容:\n{_resp.text}")
logger.info("课程列表读取完毕...")
return decode_course_list(_resp.text)
course_list = decode_course_list(_resp.text)

_interaction_url = "https://mooc2-ans.chaoxing.com/mooc2-ans/visit/interaction"
_interaction_resp = _session.get(_interaction_url)
course_folder = decode_course_folder(_interaction_resp.text)
for folder in course_folder:
_data = {
"courseType": 1,
"courseFolderId": folder["id"],
"query": "",
"superstarClass": 0
}
_resp = _session.post(_url, data=_data)
course_list += decode_course_list(_resp.text)
return course_list

def get_course_point(self, _courseid, _clazzid, _cpi):
_session = init_session()
Expand Down
12 changes: 12 additions & 0 deletions api/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ def decode_course_list(_text):
_course_list.append(_course_detail)
return _course_list

def decode_course_folder(_text):
logger.trace("开始解码二级课程列表...")
_soup = BeautifulSoup(_text, "lxml")
_raw_courses = _soup.select("ul.file-list>li")
_course_folder_list = list()
for course in _raw_courses:
if course.attrs["fileid"]:
_course_folder_detail = {}
_course_folder_detail["id"] = course.attrs["fileid"]
_course_folder_detail["rename"] = course.select_one("input.rename-input").attrs["value"]
_course_folder_list.append(_course_folder_detail)
return _course_folder_list

def decode_course_point(_text):
logger.trace("开始解码章节列表...")
Expand Down

0 comments on commit c32b360

Please sign in to comment.