def _login(self): action_chains = ActionChains(self.driver) logindata = getlogindata() #log_fp.write('\n' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) + '\n') #log_fp.write('登录信息:' + logindata[0].strip(' \t\n') + logindata[1].strip(' \t\n') + '\n') # 访问登陆界面并选择机构 url = "https://passport2.chaoxing.com/login?refer=http://i.mooc.chaoxing.com" self.driver.get(url) self.__wait.until(EC.presence_of_element_located((By.XPATH, '//a[@id="selectSchoolA"]'))) school_select = self.driver.find_element_by_xpath('//a[@id="selectSchoolA"]') action_chains.move_to_element(school_select) school_select.click() self.__wait.until(EC.presence_of_element_located((By.XPATH, '//input[@id="searchSchool1"]'))) school_input = self.driver.find_element_by_xpath('//input[@id="searchSchool1"]') school_input.send_keys(logindata[0].strip(' \t\n')) search = self.driver.find_element_by_xpath('//div[@id="dialog1"]/div/div[1]/ul/li[2]/input[2]') action_chains.move_to_element(search) search.click() self.__wait.until(EC.presence_of_element_located( (By.XPATH, '//div[@id="dialog2"]/div/div[2]/div/ul/li[1]/span/a'))) school_bn = self.driver.find_element_by_xpath('//div[@id="dialog2"]/div/div[2]/div/ul/li[1]/span/a') action_chains.move_to_element(school_bn) school_bn.click() self.__wait.until(EC.presence_of_element_located((By.XPATH, '//span[@id="schoolName2"]'))) school_name = self.driver.find_element_by_xpath('//span[@id="schoolName2"]').get_attribute('textContent') print(COLOR.DISPLAY, 'check your school name:', school_name, COLOR.END) #log_fp.write('now url:' + self.driver.current_url) self.driver.find_element_by_xpath('//input[@class="zl_input"]').send_keys(logindata[1].strip(' \t\n')) self.driver.find_element_by_xpath('//input[@class="zl_input2"]').send_keys(logindata[2].strip(' \t\n')) # 获取验证码,填写并点击登录 while 1: img = self.driver.find_element_by_id('numVerCode') img.screenshot('login_vercode.png') if SYSTEM == 0: # Win img = Image.open('login_vercode.png') img.show() else: p=Popen(['./viu', 'login_vercode.png']) p.communicate() sleep(1.5) numVerCode = input(COLOR.NOTE + "please input the vercode:" + COLOR.END) self.driver.find_element_by_id('numcode').send_keys(numVerCode) self.driver.find_element_by_xpath('//input[@class="zl_btn_right"]').click() #log_fp.write("now url:" + self.driver.current_url + '\n') if 'http://i.mooc.chaoxing.com/space/index' not in self.driver.current_url: print(COLOR.ERR, 'wrong vercode, login failed, please retry', COLOR.END) else: break
def perform(mode, rate, noans_num): #处理账号信息 print(COLOR.DISPLAY + 'Welcome To Multi-Autocx!' + COLOR.END) # 读取 手机号+密码 弹出多个弹窗 lt_phone = getlogindata_phone() for i in range(len(lt_phone) // 2): logindata = "" try: for j in range(i * 2, (i + 1) * 2): logindata += (lt_phone[j].strip(' \n')) + ',' except IndexError: print(' Sorry,no info') break # print(logindata) # args_lt = 'python3 ./login_courses.py '+logindata[0:-1]+' '+str(mode)+' '+str(rate)+' &' args_lt = [ 'python3', 'login_courses.py', logindata[0:-1], str(mode), str(rate), str(noans_num), '&' ] sub_ps = StartAutoCX(args_lt) sub_ps.work() sleep(2) # 读取 机构账号 需要输入验证码 每次处理一个 按任意键后处理下一个 lt = getlogindata() for i in range(len(lt) // 3): logindata = "" try: for j in range(i * 3, (i + 1) * 3): logindata += (lt[j].strip(' \n')) + ',' except IndexError: print(' Sorry,no info') break # print(logindata) args_lt = [ 'python3', 'login_courses.py', logindata[0:-1], str(mode), str(rate), str(noans_num), '&' ] sub_ps = StartAutoCX(args_lt) sub_ps.work() sleep(2) #input(COLOR.OK+' please press any key to continue'+COLOR.END) print(COLOR.DISPLAY + 'Now you can exit this program! Good luck!' + COLOR.END)
def perform(mode, rate): #处理账号信息 print(COLOR.DISPLAY + 'Welcome To Multi-Autocx!' + COLOR.END) # 读取 手机号+密码 弹出多个弹窗 lt_phone = getlogindata_phone() for i in range(len(lt_phone) // 2): logindata = "" try: for j in range(i * 2, (i + 1) * 2): logindata += (lt_phone[j].strip(' \n')) + ',' except IndexError: print(' Sorry,no info') break # print(logindata) Popen('start cmd /k python login_courses.py ' + logindata[0:-1] + ' ' + str(mode) + ' ' + str(rate), shell=True) sleep(2) # 读取 机构账号 需要输入验证码 每次处理一个 按任意键后处理下一个 lt = getlogindata() for i in range(len(lt) // 3): logindata = "" try: for j in range(i * 3, (i + 1) * 3): logindata += (lt[j].strip(' \n')) + ',' except IndexError: print(' Sorry,no info') break # print(logindata) Popen('start cmd /k python login_courses.py ' + logindata[0:-1] + ' ' + str(mode) + ' ' + str(rate), shell=True) input(COLOR.OK + ' please press any key to continue' + COLOR.END) print(COLOR.DISPLAY + 'Now you can exit this program! Good luck!' + COLOR.END) sleep(1.5)