update:优化ua配置

This commit is contained in:
Cordell Tippy
2025-03-28 23:36:25 +08:00
parent d04003d0c3
commit bcbd1a0170
3 changed files with 13 additions and 16 deletions

View File

@@ -43,7 +43,7 @@ class BrowserManager:
extension_path = self._get_extension_path()
co.add_extension(extension_path)
except FileNotFoundError as e:
info(f"警告: {e}")
error(f"加载插件失败,警告: {e}")
# 设置User-Agent
if DYNAMIC_USERAGENT:
@@ -51,9 +51,11 @@ class BrowserManager:
user_agent = get_random_user_agent()
info(f"使用动态User-Agent: {user_agent}")
co.set_user_agent(user_agent)
else:
elif BROWSER_USER_AGENT:
info(f"使用固定User-Agent: {BROWSER_USER_AGENT}")
co.set_user_agent(BROWSER_USER_AGENT)
else:
info("不配置User-Agent")
co.set_pref("credentials_enable_service", False)
co.set_argument("--hide-crash-restore-bubble")
@@ -66,7 +68,7 @@ class BrowserManager:
co.set_pref("webgl.vendor", "NVIDIA Corporation")
co.set_pref(
"webgl.renderer",
"ANGLE (NVIDIA, NVIDIA GeForce RTX 3070 Direct3D11 vs_5_0 ps_5_0)",
"ANGLE (NVIDIA, NVIDIA GeForce RTX 3060 Direct3D11 vs_5_0 ps_5_0)",
)
co.set_pref("navigator.plugins.length", 5)
co.set_pref("navigator.hardwareConcurrency", 8)
@@ -84,7 +86,9 @@ class BrowserManager:
co.set_pref("screen.height", 1080)
co.set_pref("screen.pixelDepth", 24)
co.auto_port()
co.headless(BROWSER_HEADLESS) # 生产环境使用无头模式
# 生产环境使用无头模式
co.headless(BROWSER_HEADLESS)
# Mac 系统特殊处理
if sys.platform == "darwin" or sys.platform == "linux":
@@ -101,7 +105,7 @@ class BrowserManager:
proxy_string += f"{PROXY_HOST}:{PROXY_PORT}"
info(f"使用代理: {PROXY_TYPE} {PROXY_HOST}:{PROXY_PORT} 账号/密码: {PROXY_USERNAME}:{PROXY_PASSWORD}")
info(f"使用代理: {PROXY_TYPE} {proxy_string}")
co.set_argument(f'--proxy-server={proxy_string}')
self.browser = Chromium(co)

View File

@@ -155,17 +155,10 @@ def sign_up_account(browser, tab, account_info):
EmailVerificationHandler.create_zmail_email(account_info)
tab.get(SIGN_UP_URL)
time.sleep(random.uniform(1, 3))
tab.wait(2)
wait_count = 1
while True:
if tab.ele("@name=first_name"):
break
if tab.ele("@name=cf-turnstile-response"):
error("开屏就是检测啊大佬你的IP或UA需要换一下了啊有问题了...要等一下")
time.sleep(random.uniform(3, 5))
info(f'{wait_count} 次等待...')
wait_count += 1
if tab.ele("@name=cf-turnstile-response"):
error("开屏就是检测啊大佬你的IP或UA需要换一下了啊有问题了...要等一下")
try:
if tab.ele("@name=first_name"):

View File

@@ -332,7 +332,7 @@
<small class="text-muted">True=无界面运行浏览器False=显示浏览器界面</small>
</div>
<div class="mb-3">
<label for="dynamic-useragent" class="form-label">动态User-Agent</label>
<label for="dynamic-useragent" class="form-label">动态User-Agent(先不要配置)</label>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch"
id="dynamic-useragent" disabled>