From 1d9ce1966a3ff6f7d088495cddb54feaef35f4c9 Mon Sep 17 00:00:00 2001 From: chenjunxue <1523825571@qq.com> Date: Wed, 12 Aug 2020 09:51:56 +0800 Subject: [PATCH] 2.0.6 增加try,保证浏览器关闭 --- conf/config.yaml | 4 ++-- core/monitor.py | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------- 2 files changed, 84 insertions(+), 75 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 917b3b9..9218b65 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -4,5 +4,5 @@ SERVER: reconnect_interval: 3 VERSION: - code: 95 - name: 2.0.5 \ No newline at end of file + code: 96 + name: 2.0.6 \ No newline at end of file diff --git a/core/monitor.py b/core/monitor.py index 19b5cb7..79e3749 100644 --- a/core/monitor.py +++ b/core/monitor.py @@ -160,80 +160,89 @@ class Monitor(callback.CallBack): chrome_options.add_argument(f'user-agent="{user_agent}"') # 创建浏览器对象 browser = webdriver.Chrome(desired_capabilities=capabilities, options=chrome_options) - self.onChangEnv(email, 'changeInitFinger', '初始设备指纹') - if cookie is not None and cookie != '': - self.onChangEnv(email, 'changeInitCookies', '初始化cookies') - print(email, '导入cookie') - browser.get(mainUrl) - from utils.encpass import back_cookies - cookies = back_cookies(cookie) - for cookie in cookies: - print(cookie['name'], cookie['value']) - browser.add_cookie(cookie) - browser.get(mainUrl) - else: + try: + self.onChangEnv(email, 'changeInitFinger', '初始设备指纹') + if cookie is not None and cookie != '': + self.onChangEnv(email, 'changeInitCookies', '初始化cookies') + print(email, '导入cookie') + browser.get(mainUrl) + from utils.encpass import back_cookies + cookies = back_cookies(cookie) + for cookie in cookies: + print(cookie['name'], cookie['value']) + browser.add_cookie(cookie) + browser.get(mainUrl) + else: + browser.get(mainUrl) + print(email, '点击帐号input') + browser.find_element_by_xpath('//*[@id="m_login_email"]').click() + print(email, '输入帐号') + browser.find_element_by_xpath('//*[@id="m_login_email"]').send_keys(email) + print(email, '点击密码input') + browser.find_element_by_xpath('//*[@id="m_login_password"]').click() + print(email, '输入密码') + browser.find_element_by_xpath('//*[@id="m_login_password"]').send_keys(password) + browser.find_element_by_xpath('//*[@id="u_0_4"]/button').click() + i = 0 + while browser.current_url == mainUrl: + time.sleep(2) + i += 1 + if i >= 3: + break + else: + print(email, '等待页面', browser.current_url) + continue + if 'save-device' in browser.current_url and 'checkpoint' not in browser.current_url: + self.onChangEnv(email, 'changeSaveFinger', '保存设备指纹') + print(email, '保存设备点击ok') + browser.find_element_by_xpath( + '//*[@id="root"]/div[1]/div/div/div[3]/div[2]/form/div/button').click() + # user_agent_ = browser.execute_script("return navigator.userAgent") # 获取ua头部 + user_agent_ = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' # 因为协议初始化必须要PCua头部 + print(email, '提取user_agent_', user_agent_) + from utils.encpass import deal_cookies + cookie_ = deal_cookies(browser.get_cookies()) + print(email, '提取cookies', cookie_) + print("判断连接", browser.current_url) + time.sleep(2) + if 'checkpoint' in browser.current_url: + self.onChangEnv(email, 'changeError', '登录失败:帐号封锁') + browser.quit() + return False, email, password, cookie_, user_agent_ + if 'login_attempt' in browser.current_url: + self.onChangEnv(email, 'changeError', '登录失败:帐号密码错误') + browser.quit() + return False, email, password, cookie_, user_agent_ + if 'c_user' not in cookie_: + self.onChangEnv(email, 'changeError', '登录失败,请检查帐号密码,或者重试') + browser.quit() + return False, email, password, cookie_, user_agent_ browser.get(mainUrl) - print(email, '点击帐号input') - browser.find_element_by_xpath('//*[@id="m_login_email"]').click() - print(email, '输入帐号') - browser.find_element_by_xpath('//*[@id="m_login_email"]').send_keys(email) - print(email, '点击密码input') - browser.find_element_by_xpath('//*[@id="m_login_password"]').click() - print(email, '输入密码') - browser.find_element_by_xpath('//*[@id="m_login_password"]').send_keys(password) - browser.find_element_by_xpath('//*[@id="u_0_4"]/button').click() - i = 0 - while browser.current_url == mainUrl: - time.sleep(2) - i += 1 - if i >= 3: - break - else: - print(email, '等待页面', browser.current_url) - continue - if 'save-device' in browser.current_url and 'checkpoint' not in browser.current_url: - self.onChangEnv(email, 'changeSaveFinger', '保存设备指纹') - print(email, '保存设备点击ok') - browser.find_element_by_xpath('//*[@id="root"]/div[1]/div/div/div[3]/div[2]/form/div/button').click() - # user_agent_ = browser.execute_script("return navigator.userAgent") # 获取ua头部 - user_agent_ = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36' # 因为协议初始化必须要PCua头部 - print(email, '提取user_agent_', user_agent_) - from utils.encpass import deal_cookies - cookie_ = deal_cookies(browser.get_cookies()) - print(email, '提取cookies', cookie_) - print("判断连接", browser.current_url) - time.sleep(2) - if 'checkpoint' in browser.current_url: - self.onChangEnv(email, 'changeError', '登录失败:帐号封锁') - browser.close() - return False, email, password, cookie_, user_agent_ - if 'login_attempt' in browser.current_url: - self.onChangEnv(email, 'changeError', '登录失败:帐号密码错误') - browser.close() - return False, email, password, cookie_, user_agent_ - if 'c_user' not in cookie_: - self.onChangEnv(email, 'changeError', '登录失败,请检查帐号密码,或者重试') - browser.close() - return False, email, password, cookie_, user_agent_ - browser.get(mainUrl) - page_source = browser.page_source - if 'News Feed' in page_source: - click_list = ['News Feed', 'Friend Requests', 'Notifications', 'Search', 'More'] - elif '动态消息' in page_source: - click_list = ['动态消息', '加好友请求', '通知', '搜索', '更多'] - else: - self.onChangEnv(email, 'changeError', '未知语言类型,请联系小陈添加') - browser.close() - return False, email, password, cookie_, user_agent_ - action_list = random.sample(click_list, 5) - print('随机动作', action_list) - for i, action in enumerate(action_list): - print(email, action) - self.onChangEnv(email, 'changeMatching', f'匹配设备指纹{i + 1}...') - browser.find_element_by_name(action).click() - browser.get('https://m.facebook.com/home.php') - browser.close() - return True, email, password, cookie_, user_agent_ + page_source = browser.page_source + if 'News Feed' in page_source: + click_list = ['News Feed', 'Friend Requests', 'Notifications', 'Search', 'More'] + elif '动态消息' in page_source: + click_list = ['动态消息', '加好友请求', '通知', '搜索', '更多'] + else: + self.onChangEnv(email, 'changeError', '未知语言类型,请联系小陈添加') + browser.quit() + return False, email, password, cookie_, user_agent_ + action_list = random.sample(click_list, 5) + print('随机动作', action_list) + for i, action in enumerate(action_list): + print(email, action) + self.onChangEnv(email, 'changeMatching', f'匹配设备指纹{i + 1}...') + browser.find_element_by_name(action).click() + browser.get('https://m.facebook.com/home.php') + browser.quit() + return True, email, password, cookie_, user_agent_ + except Exception as err: + self.onChangEnv(email, 'changeError', str(err)) + browser.quit() + return False, email, password, cookie, user_agent + finally: + browser.quit() + return False, email, password, cookie, user_agent def logout(self, email): try: -- libgit2 0.24.0