add:系统配置增加支持proxy选项

This commit is contained in:
ddCat
2025-03-28 10:29:28 +08:00
parent 495dce3fd9
commit 36101daae3
6 changed files with 378 additions and 58 deletions

View File

@@ -7,7 +7,14 @@ from config import (
BROWSER_PATH,
BROWSER_HEADLESS,
BROWSER_PROXY,
DYNAMIC_USERAGENT
DYNAMIC_USERAGENT,
USE_PROXY,
PROXY_TYPE,
PROXY_HOST,
PROXY_PORT,
PROXY_USERNAME,
PROXY_PASSWORD,
PROXY_TIMEOUT
)
import random
import time
@@ -88,11 +95,25 @@ class BrowserManager:
co.set_argument("--no-sandbox")
co.set_argument("--disable-gpu")
# 添加代理设置
if USE_PROXY and PROXY_HOST and PROXY_PORT:
proxy_string = f"{PROXY_TYPE}://"
# 如果有认证信息
if PROXY_USERNAME and PROXY_PASSWORD:
proxy_string += f"{PROXY_USERNAME}:{PROXY_PASSWORD}@"
proxy_string += f"{PROXY_HOST}:{PROXY_PORT}"
info(f"使用代理: {PROXY_TYPE} {PROXY_HOST}:{PROXY_PORT} 账号/密码: {PROXY_USERNAME}:{PROXY_PASSWORD}")
co.set_argument(f'--proxy-server={proxy_string}')
self.browser = Chromium(co)
info("浏览器初始化成功")
except Exception as e:
error(f"浏览器初始化失败: {str(e)}")
return self.browser
def _get_extension_path(self):
"""获取插件路径"""
root_dir = os.getcwd()