增加了代理平台和日志
This commit is contained in:
@@ -9,18 +9,19 @@ from loguru import logger
|
||||
|
||||
def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str]:
|
||||
"""
|
||||
验证代理是否可用,依次验证:
|
||||
1. 斗鱼主站 www.douyu.com(登录目标)
|
||||
2. 极验接口 api.geetest.com(极验验证瓶颈)
|
||||
验证代理是否可用,只验证斗鱼主站可达。
|
||||
|
||||
两关都过才算可用。
|
||||
不再验证极验接口,原因:
|
||||
1. 极验接口验证耗时 5-8秒,对短效代理是巨大浪费
|
||||
2. 极验限流导致大量代理被误判为不可用
|
||||
3. 登录流程中极验验证本身会检测代理到极验的连通性
|
||||
|
||||
Returns:
|
||||
(是否可用, 消息)
|
||||
"""
|
||||
proxies = {'http': proxy_url, 'https': proxy_url}
|
||||
|
||||
# ── 第1关:斗鱼主站 ──
|
||||
# ── 斗鱼主站可达性验证 ──
|
||||
try:
|
||||
response = requests.get(
|
||||
'https://www.douyu.com',
|
||||
@@ -29,6 +30,7 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
|
||||
headers={'User-Agent': 'Mozilla/5.0'},
|
||||
)
|
||||
response.raise_for_status()
|
||||
return True, '代理可用 → 斗鱼可达'
|
||||
except Exception as exc:
|
||||
err_msg = str(exc)
|
||||
if 'Tunnel connection failed' in err_msg or '503' in err_msg:
|
||||
@@ -40,26 +42,6 @@ def verify_proxy_url(proxy_url: str, timeout: tuple = (5, 8)) -> tuple[bool, str
|
||||
logger.debug(f"代理验证失败 [{proxy_url}]: 斗鱼主站不可达: {detail}")
|
||||
return False, detail
|
||||
|
||||
# ── 第2关:极验接口 ──
|
||||
try:
|
||||
response = requests.get(
|
||||
'https://api.geetest.com',
|
||||
proxies=proxies,
|
||||
timeout=timeout,
|
||||
headers={'User-Agent': 'Mozilla/5.0'},
|
||||
# geetest 首页可能返回 4xx,只要能连上就算通
|
||||
allow_redirects=True,
|
||||
)
|
||||
return True, '代理可用 → 斗鱼+极验'
|
||||
except Exception as exc:
|
||||
err_msg = str(exc)
|
||||
if 'timed out' in err_msg.lower():
|
||||
detail = '极验接口超时'
|
||||
else:
|
||||
detail = f'极验不可达: {type(exc).__name__}'
|
||||
logger.debug(f"代理验证失败 [{proxy_url}]: 斗鱼可达但{detail}")
|
||||
return False, detail
|
||||
|
||||
|
||||
def verify_proxies_concurrent(
|
||||
proxy_urls: list[str],
|
||||
|
||||
Reference in New Issue
Block a user