初始手动版本 可用
This commit is contained in:
@@ -465,21 +465,14 @@ class EmailGenerator:
|
||||
}
|
||||
|
||||
|
||||
def get_user_agent(proxy_choice=None, custom_api=None):
|
||||
"""获取user_agent
|
||||
Args:
|
||||
proxy_choice: 代理选择 (1=本地代理, 2=全局代理)
|
||||
custom_api: 自定义代理API地址
|
||||
"""
|
||||
def get_user_agent():
|
||||
"""获取user_agent"""
|
||||
browser_manager = None
|
||||
try:
|
||||
# 使用JavaScript获取user agent
|
||||
logging.info("初始化临时浏览器以获取User-Agent...")
|
||||
browser_manager = BrowserManager()
|
||||
browser, proxy_info = browser_manager.init_browser(
|
||||
proxy_choice=proxy_choice,
|
||||
custom_api=custom_api
|
||||
)
|
||||
browser, proxy_info = browser_manager.init_browser()
|
||||
user_agent = browser.latest_tab.run_js("return navigator.userAgent")
|
||||
logging.info(f"获取到User-Agent: {user_agent}")
|
||||
proxy_host, proxy_port, proxy_username, proxy_password = proxy_info
|
||||
@@ -512,55 +505,10 @@ def print_end_message():
|
||||
if __name__ == "__main__":
|
||||
print_logo()
|
||||
browser_manager = None
|
||||
|
||||
account_sync = AccountSync()
|
||||
try:
|
||||
logging.info("\n=== 初始化程序 ===")
|
||||
|
||||
# 选择账号同步API
|
||||
print("\n请选择账号同步API:")
|
||||
print("1. 听泉助手池")
|
||||
print("2. 高质量号池")
|
||||
|
||||
while True:
|
||||
try:
|
||||
sync_api_choice = int(input("请输入选项 (1 或 2): ").strip())
|
||||
if sync_api_choice in [1, 2]:
|
||||
break
|
||||
else:
|
||||
print("无效的选项,请重新输入")
|
||||
except ValueError:
|
||||
print("请输入有效的数字")
|
||||
|
||||
# 根据选择创建AccountSync实例
|
||||
account_sync = AccountSync(api_choice=sync_api_choice)
|
||||
|
||||
# 选择代理模式
|
||||
print("\n请选择代理模式:")
|
||||
print("1. 本地代理")
|
||||
print("2. 全局代理")
|
||||
print("3. 自定义代理API")
|
||||
|
||||
while True:
|
||||
try:
|
||||
proxy_choice = int(input("请输入选项 (1、2 或 3): ").strip())
|
||||
if proxy_choice in [1, 2, 3]:
|
||||
break
|
||||
else:
|
||||
print("无效的选项,请重新输入")
|
||||
except ValueError:
|
||||
print("请输入有效的数字")
|
||||
|
||||
# 如果选择自定义API,获取API地址
|
||||
custom_api = None
|
||||
if proxy_choice == 3:
|
||||
custom_api = input("请输入自定义代理API地址: ").strip()
|
||||
if not custom_api:
|
||||
print("API地址不能为空,将使用默认全局代理")
|
||||
proxy_choice = 2
|
||||
|
||||
# 将代理选择保存为全局变量,供后续使用
|
||||
global_proxy_choice = proxy_choice
|
||||
global_custom_api = custom_api
|
||||
|
||||
|
||||
# 提示用户选择操作模式
|
||||
print("\n请选择操作模式:")
|
||||
@@ -599,8 +547,8 @@ if __name__ == "__main__":
|
||||
|
||||
logging.info("正在初始化浏览器...")
|
||||
|
||||
# 获取user_agent,传递代理选择参数
|
||||
user_agent = get_user_agent(proxy_choice=global_proxy_choice, custom_api=global_custom_api)
|
||||
# 获取user_agent
|
||||
user_agent = get_user_agent()
|
||||
if not user_agent:
|
||||
logging.error("获取user agent失败,使用默认值")
|
||||
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
||||
@@ -696,20 +644,14 @@ if __name__ == "__main__":
|
||||
|
||||
logging.info("创建新的浏览器实例...")
|
||||
browser_manager = BrowserManager()
|
||||
# 使用选择的代理模式初始化浏览器
|
||||
browser, proxy_info = browser_manager.init_browser(
|
||||
user_agent,
|
||||
proxy_choice=global_proxy_choice,
|
||||
custom_api=global_custom_api
|
||||
)
|
||||
browser, proxy_info = browser_manager.init_browser(user_agent)
|
||||
|
||||
proxy_host, proxy_port, proxy_username, proxy_password, proxy_data = proxy_info
|
||||
proxy_host, proxy_port, proxy_username, proxy_password = proxy_info
|
||||
current_proxies = {
|
||||
'http': f'http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}',
|
||||
'https': f'http://{proxy_username}:{proxy_password}@{proxy_host}:{proxy_port}'
|
||||
}
|
||||
logging.info(f"API将使用相同代理: {proxy_host}:{proxy_port}")
|
||||
logging.info(f"API将使用相同代理: {proxy_data}")
|
||||
|
||||
# 生成邮箱
|
||||
email_generator = EmailGenerator(selected_domain=selected_domain) # 传递选定的域名
|
||||
@@ -735,61 +677,59 @@ if __name__ == "__main__":
|
||||
timeout_accounts += 1
|
||||
continue
|
||||
|
||||
# 执行注册流程
|
||||
registration_result = sign_up_account(browser, tab, registration_start_time)
|
||||
if not registration_result:
|
||||
logging.warning("注册过程失败或超时,跳过当前账号,继续下一个...")
|
||||
continue
|
||||
if sign_up_account(browser, tab, registration_start_time):
|
||||
# 检查是否超时
|
||||
if check_timeout(registration_start_time):
|
||||
logging.warning("放弃当前注册,继续下一个账号")
|
||||
timeout_accounts += 1
|
||||
continue
|
||||
|
||||
logging.info("正在获取会话令牌...")
|
||||
token = get_cursor_session_token(tab, start_time=registration_start_time)
|
||||
if token:
|
||||
# 检查是否超时
|
||||
if check_timeout(registration_start_time):
|
||||
logging.warning("放弃当前注册,继续下一个账号")
|
||||
timeout_accounts += 1
|
||||
continue
|
||||
|
||||
logging.info("更新认证信息...")
|
||||
|
||||
logging.info("重置机器码...")
|
||||
|
||||
# 检查是否超时
|
||||
if check_timeout(registration_start_time):
|
||||
logging.warning("放弃当前注册,继续下一个账号")
|
||||
timeout_accounts += 1
|
||||
continue
|
||||
|
||||
logging.info("正在获取会话令牌...")
|
||||
token = get_cursor_session_token(tab, start_time=registration_start_time)
|
||||
if not token:
|
||||
logging.error("获取会话令牌失败,跳过当前注册,继续下一个账号...")
|
||||
continue
|
||||
|
||||
|
||||
logging.info(f"API将使用相同代理: {proxy_host}:{proxy_port}")
|
||||
|
||||
# 检查是否超时
|
||||
if check_timeout(registration_start_time):
|
||||
logging.warning("放弃当前注册,继续下一个账号")
|
||||
timeout_accounts += 1
|
||||
continue
|
||||
|
||||
logging.info("更新认证信息...")
|
||||
logging.info("重置机器码...")
|
||||
|
||||
logging.info(f"API将使用相同代理: {proxy_host}:{proxy_port}")
|
||||
# 保存成功注册的账号信息
|
||||
account_data = {
|
||||
"email": account,
|
||||
"password": password,
|
||||
"token": token,
|
||||
"register_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
'user_agent': user_agent,
|
||||
'proxy_host': proxy_host,
|
||||
'proxy_port': proxy_port,
|
||||
'proxy_username': proxy_username,
|
||||
'proxy_password': proxy_password
|
||||
}
|
||||
|
||||
# 保存成功注册的账号信息
|
||||
account_data = {
|
||||
"email": account,
|
||||
"password": password,
|
||||
"token": token,
|
||||
"register_time": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
'user_agent': user_agent,
|
||||
'proxy_host': proxy_host,
|
||||
'proxy_port': proxy_port,
|
||||
'proxy_username': proxy_username,
|
||||
'proxy_password': proxy_password,
|
||||
'proxy_data': proxy_data
|
||||
}
|
||||
|
||||
logging.info("更新认证信息...")
|
||||
|
||||
# 添加到成功账号列表
|
||||
successful_accounts.append(account_data)
|
||||
|
||||
# # 同步到服务器
|
||||
if account_sync.sync_account(account_data):
|
||||
logging.info("账号已成功同步到服务器")
|
||||
else:
|
||||
logging.warning("账号同步到服务器失败")
|
||||
logging.info("更新认证信息...")
|
||||
|
||||
# 添加到成功账号列表
|
||||
successful_accounts.append(account_data)
|
||||
|
||||
# # 同步到服务器
|
||||
if account_sync.sync_account(account_data):
|
||||
logging.info("账号已成功同步到服务器")
|
||||
else:
|
||||
logging.warning("账号同步到服务器失败")
|
||||
|
||||
|
||||
else:
|
||||
logging.error("获取会话令牌失败,注册流程未完成")
|
||||
|
||||
# 计算本次注册用时
|
||||
registration_elapsed = time.time() - registration_start_time
|
||||
|
||||
Reference in New Issue
Block a user