예제 #1
0
 def work(self):
     global chrome_pid
     with StartDriver() as chrome_driver:
         #self.driver = startchrome()
         self.driver = chrome_driver.driver
         chrome_pid = chrome_driver.chrome_pid
         self.__wait = WebDriverWait(self.driver, 20)
         print(COLOR.DISPLAY, 'Lauching…', COLOR.END)
         self._login()
         # print(self.driver.current_url)
         courses_lt = self._choose_course()
         self._call_SC(courses_lt)
     if self._sc_out_fp != None:
         self._sc_out_fp.flush()
         self._sc_out_fp.close()
예제 #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对象转换为字典对象

        global chrome_pid
        with StartDriver() as chrome_driver:
            # '--remote-debugging-port=9222') # 配置chrome启动参数并启动
            driver = chrome_driver.driver
            chrome_pid = chrome_driver.chrome_pid
            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._sc_out_fp)
                    singlecourse.work()
            else:
                while (1):
                    goal = self._choose_course(courses_lt)
                    if goal == 0:
                        exit(0)
                    print(COLOR.OK + ' LOGIN_FINISHED' + COLOR.END)
                    singlecourse = SC(driver, base_url + goal[0], goal[1],
                                      self.pattern, self._sc_out_fp)
                    singlecourse.work()
                    if SYSTEM == 1:
                        break
        if self._sc_out_fp != None:
            self._sc_out_fp.flush()
            self._sc_out_fp.close()