diff --git a/api/base.py b/api/base.py index 8cbf69b..ba57776 100644 --- a/api/base.py +++ b/api/base.py @@ -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(): @@ -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() diff --git a/api/decode.py b/api/decode.py index 7b8e423..bd08e58 100644 --- a/api/decode.py +++ b/api/decode.py @@ -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("开始解码章节列表...")