Example #1
0
    def _call_SC(self, courses_lt):
        if self.pattern == 1:
            print(COLOR.OK + ' LOGIN_FINISHED' + COLOR.END)

            for name, url in courses_lt:
                print(COLOR.NOTE + ' Course:' + name + COLOR.END)
                singlecourse = SC(self.driver, url, name, 0, self.rate,
                                  self._sc_out_fp)
                singlecourse.work()
        else:
            while 1:
                try:
                    course_id = eval(
                        input(COLOR.NOTE +
                              'please select which course by order:' +
                              COLOR.END))
                    if course_id > 0 and course_id <= len(courses_lt):
                        break
                    else:
                        print(COLOR.ERR,
                              ' invalid course order, please reinput!',
                              COLOR.END)
                except:
                    pass

            print(COLOR.OK + ' LOGIN_FINISHED' + COLOR.END)

            menu_url = courses_lt[course_id - 1][1]
            course_name = courses_lt[course_id - 1][0]
            singlecourse = SC(self.driver, menu_url, course_name, self.pattern,
                              self.rate, self._sc_out_fp)
            singlecourse.work()
Example #2
0
 def work(self):
     if self.mode == 1:
         courses_lt = self._login_by_phone()
     else:
         courses_lt = self._login()
     cookies = utils.dict_from_cookiejar(self.mysession.cookies)
     # utils.dict_from_cookiejar(cookies)把cookiejar对象转换为字典对象
     driver = startchrome()
     # '--remote-debugging-port=9222') # 配置chrome启动参数并启动
     base_url = 'https://mooc1-1.chaoxing.com'
     driver.get(base_url)
     driver.delete_all_cookies()
     for k, v in cookies.items():
         driver.add_cookie({'name': k, 'value': v})
         # print(str(k),str(v))
     # print(driver.get_cookies())
     # driver.get(base_url+goal_url)
     if self.pattern == 1:
         print(COLOR.OK + ' LOGIN_FINISHED' + COLOR.END)
         for url, name in courses_lt:
             print(COLOR.NOTE + ' Course:' + name + COLOR.END)
             singlecourse = SC(driver, base_url + url, name, 0, self.rate,
                               self._sc_out_fp)
             singlecourse.work()
     else:
         while (1):
             goal = self._choose_course(courses_lt)
             print(COLOR.OK + ' LOGIN_FINISHED' + COLOR.END)
             singlecourse = SC(driver, base_url + goal[0], goal[1],
                               self.pattern, self.rate, self._sc_out_fp)
             singlecourse.work()
     if self._sc_out_fp != None:
         self._sc_out_fp.flush()
         self._sc_out_fp.close()