feat: add proxy pool management module
This commit is contained in:
@@ -62,6 +62,15 @@ def _parse_line(line: str) -> Proxy | None:
|
||||
if not line or line.startswith("#"):
|
||||
return None
|
||||
|
||||
# 优先检查完整 URL 格式(必须在 colon-split 之前,否则会被错误匹配)
|
||||
if line.startswith(("http://", "https://", "socks5://")):
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
parsed = urlparse(line)
|
||||
return Proxy(raw=line, url=line, host=parsed.hostname or "?", port=str(parsed.port or "?"))
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
parts = line.split(":")
|
||||
if len(parts) == 4:
|
||||
host, port, user, passwd = parts
|
||||
@@ -71,14 +80,6 @@ def _parse_line(line: str) -> Proxy | None:
|
||||
host, port = parts
|
||||
url = f"http://{host}:{port}"
|
||||
return Proxy(raw=line, url=url, host=host, port=port)
|
||||
elif line.startswith(("http://", "https://", "socks5://")):
|
||||
# 从完整 URL 提取 host:port
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
parsed = urlparse(line)
|
||||
return Proxy(raw=line, url=line, host=parsed.hostname or "?", port=str(parsed.port or "?"))
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user