From 40e798187ebbbcb7713b88c77b8e5aafb6dd106f Mon Sep 17 00:00:00 2001 From: YouqingXiaozhua <843213558@qq.com> Date: Fri, 14 Feb 2020 12:02:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=81=AD=E5=96=9C=E8=AF=BE=E7=A8=8B=E7=BD=91?= =?UTF-8?q?=E7=AB=99=E5=96=9C=E6=8F=90https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index bc3eb86..8166030 100644 --- a/main.py +++ b/main.py @@ -47,9 +47,8 @@ def _get_course_page(self): # 从sep中获取Identity Key来登录课程系统,并获取课程信息 url = "http://sep.ucas.ac.cn/portal/site/16/801" r = self.session.get(url, headers=self.headers) - code = re.findall(r'"http://course.ucas.ac.cn/portal/plogin\?Identity=(.*)"', r.text)[0] + url = re.findall(r'', r.text)[0] - url = "http://course.ucas.ac.cn/portal/plogin?Identity=" + code self.headers['Host'] = "course.ucas.ac.cn" html = self.session.get(url, headers=self.headers).text return html @@ -57,13 +56,13 @@ def _get_course_page(self): def _parse_course_list(self): # 获取课程的所有URL html = self._get_course_page() - self.course_list = ['http://course.ucas.ac.cn/portal/site/' + x for x in - re.findall(r'http://course.ucas.ac.cn/portal/site/([\d]+)"', html)] + self.course_list = ['https://course.ucas.ac.cn/portal/site/' + x for x in + re.findall(r'https://course.ucas.ac.cn/portal/site/([\d]+)"', html)] def _get_all_resource_url(self): # 从课程的所有URL中获取对应的所有课件 print('读取课件中......') - base_url = 'http://course.ucas.ac.cn/access/content/group/' + base_url = 'https://course.ucas.ac.cn/access/content/group/' urls = [base_url + x.split('/')[-1] + '/' for x in self.course_list] list(map(self._get_resource_url, urls)) @@ -127,7 +126,7 @@ def _download_file(self, param): except TypeError: size_mb = 0.33 # html文件直接指定大小 :) try: - print('Start download {dic_name} >> {sub_directory}{filename} {size_mb:.2f}MB'.format(**locals())) + # print('Start download {dic_name} >> {sub_directory}{filename} {size_mb:.2f}MB'.format(**locals())) with open(save_path, 'wb') as f: for chunk in r.iter_content(chunk_size=1024): if chunk: # filter out keep-alive new chunks