parent
bc3b45acd7
commit
046bbeaedf
37
main.py
37
main.py
|
@ -25,6 +25,7 @@ import win32gui
|
|||
from mail import GoogleCodeReceiver, EmailClient
|
||||
from proxy import ProxyManagerSQLite, classifier_smartproxy
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from fake_useragent import UserAgent
|
||||
|
||||
# Windows 消息常量
|
||||
WM_MOUSEMOVE = 0x0200
|
||||
|
@ -57,18 +58,7 @@ def init_worker():
|
|||
# 全局写入锁
|
||||
write_lock = multiprocessing.Lock()
|
||||
|
||||
ua_templates = [
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:95.0) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}",
|
||||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/{webkit_version} (KHTML, like Gecko) Chrome/{chrome_version} Safari/{safari_version}"
|
||||
]
|
||||
|
||||
|
||||
# 自定义异常
|
||||
class WindowMinimizedError(Exception):
|
||||
|
@ -84,26 +74,6 @@ def is_window_minimized(hwnd):
|
|||
"""检查窗口是否最小化"""
|
||||
return win32gui.IsIconic(hwnd)
|
||||
|
||||
|
||||
def generate_user_agent():
|
||||
# 随机选择一个Chrome的UA模板
|
||||
selected_template = random.choice(ua_templates)
|
||||
|
||||
# 随机生成 WebKit、Safari 和 Chrome 版本号
|
||||
webkit_version = f"{random.randint(500, 599)}.{random.randint(0, 99)}"
|
||||
safari_version = f"{random.randint(500, 599)}.{random.randint(0, 99)}"
|
||||
chrome_version = f"{random.randint(40, 99)}.{random.randint(0, 2999)}.{random.randint(0, 99)}"
|
||||
|
||||
# 填充模板中的动态部分并生成完整的UA
|
||||
user_agent = selected_template.format(
|
||||
webkit_version=webkit_version,
|
||||
safari_version=safari_version,
|
||||
chrome_version=chrome_version
|
||||
)
|
||||
|
||||
return user_agent
|
||||
|
||||
|
||||
def random_sleep(tab, min_seconds=1, max_seconds=3):
|
||||
"""在 min_seconds 和 max_seconds 之间随机停顿"""
|
||||
tab.wait(random.uniform(min_seconds, max_seconds))
|
||||
|
@ -786,7 +756,8 @@ def main(email_account, email_password, old_recovery_email, new_password, new_re
|
|||
options.add_extension(plugin_path)
|
||||
|
||||
# 使用随机生成的User-Agent
|
||||
random_user_agent = generate_user_agent()
|
||||
ua = UserAgent()
|
||||
random_user_agent = ua.chrome
|
||||
options.set_user_agent(user_agent=random_user_agent)
|
||||
|
||||
# 随机分配一个端口号
|
||||
|
|
Loading…
Reference in New Issue