Upload browser_captcha.py
Browse files
src/services/browser_captcha.py
CHANGED
|
@@ -6,10 +6,16 @@ import asyncio
|
|
| 6 |
import time
|
| 7 |
import re
|
| 8 |
from typing import Optional, Dict
|
| 9 |
-
from playwright.async_api import async_playwright, Browser, BrowserContext
|
| 10 |
|
| 11 |
from ..core.logger import debug_logger
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
def parse_proxy_url(proxy_url: str) -> Optional[Dict[str, str]]:
|
| 15 |
"""解析代理URL,分离协议、主机、端口、认证信息
|
|
@@ -105,6 +111,11 @@ class BrowserCaptchaService:
|
|
| 105 |
return
|
| 106 |
|
| 107 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# 获取浏览器专用代理配置
|
| 109 |
proxy_url = None
|
| 110 |
if self.db:
|
|
|
|
| 6 |
import time
|
| 7 |
import re
|
| 8 |
from typing import Optional, Dict
|
|
|
|
| 9 |
|
| 10 |
from ..core.logger import debug_logger
|
| 11 |
|
| 12 |
+
# Conditionally import playwright
|
| 13 |
+
try:
|
| 14 |
+
from playwright.async_api import async_playwright, Browser, BrowserContext
|
| 15 |
+
PLAYWRIGHT_AVAILABLE = True
|
| 16 |
+
except ImportError:
|
| 17 |
+
PLAYWRIGHT_AVAILABLE = False
|
| 18 |
+
|
| 19 |
|
| 20 |
def parse_proxy_url(proxy_url: str) -> Optional[Dict[str, str]]:
|
| 21 |
"""解析代理URL,分离协议、主机、端口、认证信息
|
|
|
|
| 111 |
return
|
| 112 |
|
| 113 |
try:
|
| 114 |
+
# 检查 Playwright 是否可用
|
| 115 |
+
if not PLAYWRIGHT_AVAILABLE:
|
| 116 |
+
debug_logger.log_error("[BrowserCaptcha] ❌ Playwright 不可用,请使用 YesCaptcha 服务")
|
| 117 |
+
raise ImportError("Playwright 未安装,请使用 YesCaptcha 服务")
|
| 118 |
+
|
| 119 |
# 获取浏览器专用代理配置
|
| 120 |
proxy_url = None
|
| 121 |
if self.db:
|