def test_login(self): u'''登录''' driver = self.driver driver.get(self.url) l_d = login_data.login_data() login.login(driver, l_d['uname'], l_d['pwd']) time.sleep(2)
def log_in(): banner() print 'Login:\n' uid = raw_input('ID>') private_key = raw_input('Private Key Path>') logged_in_user = login.login(uid, private_key) return logged_in_user
def test_adduser(self): u'''新增会员''' driver = self.driver driver.get(self.url) l_d = login_data.login_data() login.login(driver, l_d['uname'], l_d['pwd']) a_d = adduser_data.adduser() time.sleep(3) #调用location.py文件的定位方法 dr = location #进入用户管理 dr.findXpath(driver, '//*[@id="side-menu"]/li[3]/a').click() dr.findXpath(driver, '//*[@id="side-menu"]/li[3]/ul/li[1]/a').click() time.sleep(2) #进入新增页面 driver.switch_to.frame('iframe1') dr.findId(driver, 'button_post_insert').click() time.sleep(2) #定位用户名 dr.findId(driver, 'login_name').send_keys(a_d['addname']) #定位密码 dr.findId(driver, 'password').send_keys(a_d['addpwd']) #定位确认密码 dr.findId(driver, 'confirmNewPassword').send_keys(a_d['addpwd']) #定位姓名 dr.findId(driver, 'name').send_keys(a_d['addname']) #系统权限 dr.findXpath( driver, '//*[@id="user_form"]/fieldset[3]/div[2]/div/div/ul').click() dr.findXpath( driver, '//*[@id="user_form"]/fieldset[3]/div[2]/div/div/div/ul/li').click( ) #定位用户角色复选框 checkboxs = dr.findsCss(driver, 'input[type=checkbox]') for checkbox in checkboxs: checkbox.click() time.sleep(1)
def do_login(self): if self.username_le.text() and self.password_le.text(): result = login( username=self.username_le.text(), password=self.password_le.text()) # assert result['token'], '本地无记录' logging.debug(result) try: if result['result']['token']: table = 'user' # 写入缓存 mine.update_item('username', self.username_le.text()) mine.update_item('token', result['result']['token']) if not utils.get_user_info(table, self.username_le.text()): # 没有用户直接插入 dict = {'username': self.username_le.text(), 'token': result['token']} sql = "insert into user(username,token) values ('%s','%s');" sqlite_db.transaction(sql) times = ['00:15:00', '00:30:00', '01:00:00'] for time in times: sqlite_db.transaction( "insert into Reminder(username,time) values ('%s','%s');" % (dict['username'], time)) # 已有用户更新数据 else: value_dict = {'token': result['result']['token']} filter_list = [ ['username', '=', self.username_le.text()]] sql = be_sql().update_sql(table=table, value_dict=value_dict, filter_list=filter_list) sqlite_db.transaction(sql) try: # 发射信号 self.login_signal.emit(self.username_le.text()) except Exception as e: logging.error(e) self.close() else: Toast(self).show_toast("{}".format(result['msg'])) except Exception as e: logging.error(e) elif not self.username_le.text(): Toast(self).show_toast("请输入账号") elif not self.password_le.text(): Toast(self).show_toast("请输入密码")
def do_run(title_url, user_name, user_pwd, delay=1.0): try: driver = chrome_less() driver = login(driver, user_name, user_pwd, delay) time.sleep(2 * delay) cookie = driver.get_cookies() cookie_str = set_cookie_str(cookie) #调用get_url获取课程列表,筛除已完成课程 url_list = get_url(driver, cookie, title_url, delay)[0] time_list_coe = get_url(driver, cookie, title_url, delay)[1] print("找到了" + str(len(url_list)) + "个") count = int(input("要开几个:")) time_space = 60 - 4 * (count * delay) video_url_list = url_list[:count] time_list_coe_count = time_list_coe[:count] #调用get_course进行获取课程 video_url = [] time_list = [] for i in range(len(video_url_list)): video_url.append(get_course(video_url_list[i], cookie_str)[0]) time_list.append( int(time_list_coe_count[i] * get_course(video_url_list[i], cookie_str)[1]) + 1) if count > 15: time_list[i] = (15 / count) * time_list[i] time_i = max(time_list) print(time_i) except Exception as e: if driver: print(e) exit(0) else: return 1 #回去重新登录 finally: try: driver.quit() except: pass try: driver_video = [] for i in range(len(video_url)): if video_url[i]: driver_video.append(load_phantomjs()) driver_video[i] = login_by_cookie(driver_video[i], cookie, delay) time.sleep(3 * delay) driver_video[i].get(video_url[i]) time.sleep(3 * delay) driver_video[i].save_screenshot(r'./star.png') print("打开第" + str(i + 1) + ("个")) print("开了" + str(len(driver_video)) + "个") finally: pass try: for i in range(len(driver_video)): driver_video[i].switch_to.frame( driver_video[i].find_element_by_id('topFrame')) time.sleep(0.5) while time_i > 0: print("还剩" + str(time_i) + "分钟") for i in range(len(driver_video)): save(driver_video[i], delay) if time_space > 0: time.sleep(time_space) time_i = time_i - 1 time_list[i] = time_list[i] - 1 if time_list[i] < 0: #看完就关掉 driver_video[i].quit() driver_video.pop(i) time_list.pop(i) i = i - 1 if len(driver_video) < 15: time_space = time_space + 4 * delay print("看完了一个") finally: for i in range(len(driver_video)): driver_video[i].quit() return 0
adu = adduser_data.adduser() l_d = login_data.login_data() driver = webdriver.Chrome() driver.get('http://39.98.84.153:8881/login') #driver.maximize_window() # driver.find_element_by_id('username').clear() # driver.find_element_by_id('username').send_keys('zhengming') # # driver.find_element_by_id('password').clear() # driver.find_element_by_id('password').send_keys('zhengming') # # driver.find_element_by_id('login_btn').click() login.login(driver, l_d['uname'], l_d['pwd']) driver.switch_to.default_content() # time.sleep(2) dr = location dr.findXpath(driver, '//*[@id="side-menu"]/li[3]/a').click() # driver.find_element_by_xpath('//*[@id="side-menu"]/li[3]/a').click() # driver.find_element_by_xpath('//*[@id="side-menu"]/li[3]/ul/li[1]/a').click() # time.sleep(2) # driver.switch_to.frame('iframe1') # driver.find_element_by_id('button_post_insert').click() # # time.sleep(2) # driver.find_element_by_id('login_name').send_keys(adu['addname']) # driver.find_element_by_id('password').send_keys(adu['addpwd'])