diff --git a/main.py b/main.py index f4c4bbf..bc6798e 100644 --- a/main.py +++ b/main.py @@ -104,7 +104,7 @@ def generate_user_agent(): return user_agent -def random_sleep(tab, min_seconds=1, max_seconds=3): +def random_sleep(tab, min_seconds=0, max_seconds=2): """在 min_seconds 和 max_seconds 之间随机停顿""" tab.wait(random.uniform(min_seconds, max_seconds)) @@ -467,10 +467,11 @@ def click_use_other_account_button2(tab, next_span): # 修改辅助邮箱账号 -def modify_the_secondary_email1(tab, button, auxiliary_email_account): +def modify_the_secondary_email1(tab, auxiliary_email_account): + button = tab.ele('@@tag()=i@@text()=edit', timeout=15) button.click(by_js=True) tab.wait(2) - input = button + input = tab.ele('@type=email', timeout=15) input.clear() for char in auxiliary_email_account: input.input(char) # Enter one character at a time @@ -753,12 +754,33 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("任务被强制停止,退出主函数") return None # 直接返回 None,跳过当前任务 + if not region: + region = "ALL" # 如果没有区域信息,则使用默认区域 + + # 获取一个随机代理并传递给当前账号 + proxy = proxy_manager.get_random_proxy_by_region(region=region, remove_after_fetch=True) + + if proxy: # 如果分配成功 + proxy_host, proxy_port, proxy_user, proxy_pass = proxy['host'], proxy['port'], proxy['user'], \ + proxy['password'] + print(f"为账号 {email_account} 分配代理:{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") + + db_manager.update_record(email_account,proxy=f"{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") + else: + print(f"为账号 {email_account} 分配代理失败,跳过此账号。") + + with write_lock: + try: + print("更新剩余可用IP") + proxy_manager.export_proxies("剩下的可用IP.txt") + except Exception as e: + print(f"导出代理时发生错误: {e}") + if not proxy_host: save_log(random_number, f"没有{region}区域的代理") update_status_in_db(email_account, f"没有{region}区域代理") return False - lock = FileLock("proxy_auth_extension.lock") with lock: # 加锁,确保其他进程在解锁前无法操作 @@ -852,26 +874,20 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re click_the_login_button(tab, login_a) random_sleep(tab) - login = tab.ele('@@tag()=span@@text()=登录', timeout=10) - if login: - random_sleep(tab) - # 将随机数设置为窗口标题 - script = f"document.title = '{random_number}';" - # 执行 JS 脚本 - tab.run_js(script) - print("登录运行完毕") - save_log(random_number, "已经进入登录界面") - else: - update_status_in_db(email_account, '登录超时') - return ( - email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, - proxy_port, - proxy_username, proxy_password, region) + tab.wait(3) - random_sleep(tab) + # 将随机数设置为窗口标题 + script = f"document.title = '{random_number}';" + # 执行 JS 脚本 + tab.run_js(script) actual_title = tab.run_js("return document.title;") + print("登录运行完毕") + save_log(random_number, "已经进入登录界面") + + tab.wait(7) + save_log(random_number, f"设置标题为: {random_number}, 实际标题为: {actual_title}\n") # 获取所有 Chrome 窗口 @@ -1016,6 +1032,30 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("如果出现错误,输入密码运行完毕") save_log(random_number, "如果出现错误后,输入密码运行完毕") + + # 看下是否出现了手机号 + telephone = tab.ele("@text()=请输入电话号码,以便通过短信接收验证码。", timeout=5) + if telephone: + save_log(random_number, '接码') + update_status_in_db(email_account, '接码') + return email_account + + print("检查手机号2运行完毕") + save_log(random_number, "检查手机号2运行完毕") + + wrong = tab.ele('@@tag()=a@@text()=了解详情', timeout=5) + if wrong: + save_log(random_number, '出现账号状态异常') + update_status_in_db(email_account, '出现账号状态异常') + return ( + email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, + proxy_port, + proxy_username, proxy_password, region) + + print("检查谷歌账号是否存在异常活动完毕") + save_log(random_number, "检查谷歌账号是否存在异常活动完毕") + + # 确定密码是否被修改的开关 password_change = False @@ -1027,7 +1067,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re input_password(tab, hwnd, new_password, password_input) save_log(random_number, f"输入新密码完毕") tab.wait(7) - if tab.wait.ele_deleted('#passwordNext', timeout=10) == False: + if tab.wait.ele_deleted('#passwordNext', timeout=5) == False: update_status_in_db(email_account, '被盗') return email_account password_change = True @@ -1045,31 +1085,10 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("输入新密码运行完毕") save_log(random_number, "输入新密码运行完毕") - # 看下是否出现了手机号 - telephone = tab.ele("@text()=请输入电话号码,以便通过短信接收验证码。", timeout=5) - if telephone: - save_log(random_number, '接码') - update_status_in_db(email_account, '接码') - return email_account - - print("检查手机号2运行完毕") - save_log(random_number, "检查手机号2运行完毕") - - wrong = tab.ele('@@tag()=a@@text()=了解详情', timeout=5) - alternate_email_button = tab.ele('@text()=确认您的辅助邮箱', timeout=5) - if wrong and not alternate_email_button: - save_log(random_number, '出现账号状态异常') - update_status_in_db(email_account, '出现账号状态异常') - return ( - email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, - proxy_port, - proxy_username, proxy_password, region) - - print("检查谷歌账号是否存在异常活动完毕") - save_log(random_number, "检查谷歌账号是否存在异常活动完毕") - try: + # 使用辅助邮箱验证 + alternate_email_button = tab.ele('@text()=确认您的辅助邮箱', timeout=15) if alternate_email_button: click_alternate_email_verification_button(tab, alternate_email_button) random_sleep(tab) @@ -1100,11 +1119,10 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("我要开始修改辅助邮箱账号了") try: - button = tab.ele('@type=email', timeout=15) + button = tab.ele('@@tag()=i@@text()=edit', timeout=15) if button: - modify_the_secondary_email1(tab,button, new_recovery_email) # 使用传入的新辅助邮箱 + modify_the_secondary_email1(tab, new_recovery_email) # 使用传入的新辅助邮箱 print("修改完成") - auxiliary_email_account_change = True else: print("没有修改辅助邮箱的界面,跳过") # auxiliary_email_account_change = True @@ -1128,25 +1146,24 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re if password_change and auxiliary_email_account_change: logutGoogle(tab) - tab.wait(3) update_status_in_db(email_account, '已更改') return email_account tab.handle_alert(accept=True) - # # 点击继续按钮 - # continue_div1 = tab.ele('@text()=Continue with smart features', timeout=15) - # if continue_div1: - # try: - # click_continue_button(tab, continue_div1) - # except ElementNotFoundError as e: - # print(f"找不到继续按钮的元素:{e}") - # save_log(random_number, f"找不到继续按钮的元素:{e}") - # update_status_in_db(email_account, "请求错误,请重试") - # return ( - # email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, - # proxy_port, - # proxy_username, proxy_password, region) + # 点击继续按钮 + continue_div1 = tab.ele('@text()=Continue with smart features', timeout=15) + if continue_div1: + try: + click_continue_button(tab, continue_div1) + except ElementNotFoundError as e: + print(f"找不到继续按钮的元素:{e}") + save_log(random_number, f"找不到继续按钮的元素:{e}") + update_status_in_db(email_account, "请求错误,请重试") + return ( + email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, + proxy_port, + proxy_username, proxy_password, region) try: # 安全设置 @@ -1155,6 +1172,7 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re tab.handle_alert(accept=True) tab.get("https://myaccount.google.com/security?gar=WzEyMF0") except ElementNotFoundError as e: + print(f"找不到头像的元素:{e}") save_log(random_number, f"进入安全设置后出错:{e}") update_status_in_db(email_account,"进入安全设置的时候请求错误,请重试") return ( @@ -1169,10 +1187,6 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("进入安全设置后仍然未登录") save_log(random_number, '进入安全设置后仍然未登录') update_status_in_db(email_account, '登录失败') - return ( - email_account, email_password, old_recovery_email, new_password, new_recovery_email, proxy_host, - proxy_port, - proxy_username, proxy_password, region) try: # 如果密码没被修改 @@ -1197,7 +1211,6 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re try: if auxiliary_email_account_change: logutGoogle(tab) - tab.wait(3) update_status_in_db(email_account, '已更改') return email_account # 修改辅助邮箱2 @@ -1205,7 +1218,6 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re save_log(random_number, f"辅助邮箱是否被修改:{flag}") if flag: logutGoogle(tab) - tab.wait(3) update_status_in_db(email_account, '已更改') return email_account else: @@ -1267,10 +1279,8 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re print("辅助邮箱账号已经更改完毕") save_log(random_number, "辅助邮箱账号已经更改完毕") logutGoogle(tab) - tab.wait(3) update_status_in_db(email_account, "已更改") - return email_account - + break else: # 如果未找到验证码,点击重新发送按钮并进入下一次循环 print("未找到验证码,点击重新发送按钮") @@ -1494,35 +1504,7 @@ def run_gui(): print("停止信号已接收,中止任务!") break - # 获取邮箱和区域信息 - account_email = row[0] - region = row[9] # 假设第6列存储的是账号的区域信息 - if not region: - region = "ALL" # 如果没有区域信息,则使用默认区域 - - # 获取一个随机代理并传递给当前账号 - proxy = proxy_manager.get_random_proxy_by_region(region=region, remove_after_fetch=True) - - if proxy: # 如果分配成功 - proxy_host, proxy_port, proxy_user, proxy_pass = proxy['host'], proxy['port'], proxy['user'], \ - proxy['password'] - print(f"为账号 {account_email} 分配代理:{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") - - db_manager.update_record(account_email, - proxy=f"{proxy_host}:{proxy_port}:{proxy_user}:{proxy_pass}") - row = row[:5] + (proxy_host, proxy_port, proxy_user, proxy_pass) + row[9:] # 将代理信息加入到数据行中 - else: - print(f"为账号 {account_email} 分配代理失败,跳过此账号。") - - with write_lock: - try: - print("更新剩余可用IP") - proxy_manager.export_proxies("剩下的可用IP.txt") - except Exception as e: - print(f"导出代理时发生错误: {e}") - - update_proxy_stats() # 传递锁给子进程,并将当前账号数据传递给 main 函数 result = pool.apply_async(main, args=(row), callback=lambda result: progress_queue.put(result)) @@ -1600,6 +1582,11 @@ def run_gui(): return data + def periodic_update(): + # 每隔一定时间调用一次更新代理统计信息的函数 + update_proxy_stats() + root.after(5000, periodic_update) # 每5000毫秒(5秒)调用一次 + root = tk.Tk() root.title("程序控制界面") @@ -1643,6 +1630,8 @@ def run_gui(): lbl_proxy_stats = tk.Label(root, text="代理统计信息未加载") lbl_proxy_stats.grid(row=8, column=1, padx=5, pady=10, columnspan=2) + periodic_update() + root.protocol("WM_DELETE_WINDOW", on_closing) # 绑定窗口关闭事件 root.mainloop()