Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Fix re for icourse163
Browse files Browse the repository at this point in the history
优化中M正则,以适应含回车课程名的匹配
  • Loading branch information
SigureMo committed Nov 19, 2018
1 parent ae32e96 commit ad8767e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mooc/icourse163.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ def get_resource(term_id):
res = CANDY.post('https://www.icourse163.org/dwr/call/plaincall/CourseBean.getMocTermDto.dwr',
data=post_data).text.encode('utf_8').decode('unicode_escape')

chapters = re.findall(r'homeworks=\w+;.+id=(\d+).+name="(.+)";', res)
chapters = re.findall(r'homeworks=\w+;.+id=(\d+).+name="([\s\S]+?)";', res)
for chapter in chapters:
counter.add(0)
outline.write(chapter[1], counter, 0)

lessons = re.findall(r'chapterId=' + chapter[0] + r'.+contentType=1.+id=(\d+).+name="(.+)".+test', res)
lessons = re.findall(r'chapterId=' + chapter[0] + r'.+contentId=null.+contentType=1.+id=(\d+).+name="([\s\S]+?)"', res)
for lesson in lessons:
counter.add(1)
outline.write(lesson[1], counter, 1)

videos = re.findall(r'contentId=(\d+).+contentType=(1).+id=(\d+).+lessonId=' +
lesson[0] + r'.+name="(.+)"', res)
lesson[0] + r'.+name="([\s\S]+?)"', res)
for video in videos:
counter.add(2)
outline.write(video[3], counter, 2, sign='#')
video_list.append(Video(counter, video[3], video))
counter.reset()

pdfs = re.findall(r'contentId=(\d+).+contentType=(3).+id=(\d+).+lessonId=' +
lesson[0] + r'.+name="(.+)"', res)
lesson[0] + r'.+name="([\s\S]+?)"', res)
for pdf in pdfs:
counter.add(2)
outline.write(pdf[3], counter, 2, sign='*')
Expand All @@ -157,7 +157,7 @@ def get_resource(term_id):
counter.reset()

rich_text = re.findall(r'contentId=(\d+).+contentType=(4).+id=(\d+).+jsonContent=(.+?";);.+lessonId=' +
lesson[0] + r'.+name="(.+)"', res)
lesson[0] + r'.+name="([\s\S]+?)"', res)
for text in rich_text:
counter.add(2)
outline.write(text[4], counter, 2, sign='+')
Expand Down

0 comments on commit ad8767e

Please sign in to comment.