commit
This commit is contained in:
@@ -1,23 +1,62 @@
|
||||
"""
|
||||
大麦固定代理IP配置
|
||||
用于在无头浏览器中使用固定代理IP
|
||||
小红书代理IP配置
|
||||
用于在无头浏览器中使用代理IP防止风控
|
||||
"""
|
||||
|
||||
# 大麦固定代理IP池
|
||||
DAMAI_PROXY_POOL = [
|
||||
# 代理IP池配置
|
||||
PROXY_POOL = [
|
||||
{
|
||||
"name": "大麦代理1",
|
||||
"name": "代理01",
|
||||
"server": "http://60.188.239.186:3101", # 如果支持SOCKS5,改为 socks5://...
|
||||
"username": "46vTEIvZt",
|
||||
"password": "gM33AFND",
|
||||
"enabled": False # HTTP代理不支持HTTPS隧道,暂时禁用
|
||||
},
|
||||
{
|
||||
"name": "代理02",
|
||||
"server": "http://222.94.104.232:4201",
|
||||
"username": "46azrCOcF",
|
||||
"password": "WKyKYE6P",
|
||||
"enabled": False # HTTP代理不支持HTTPS隧道,暂时禁用
|
||||
},
|
||||
{
|
||||
"name": "代理03",
|
||||
"server": "http://125.94.108.2:4601",
|
||||
"username": "46eX9tk99",
|
||||
"password": "odtvKjpl",
|
||||
"enabled": False # HTTP代理不支持HTTPS隧道,暂时禁用
|
||||
},
|
||||
{
|
||||
"name": "代理04",
|
||||
"server": "http://113.24.66.191:3601",
|
||||
"username": "46r74jRaD",
|
||||
"password": "WjOXiXjq",
|
||||
"enabled": False # HTTP代理不支持HTTPS隧道,暂时禁用
|
||||
},
|
||||
{
|
||||
"name": "代理05",
|
||||
"server": "http://113.249.158.23:4401",
|
||||
"username": "46oKu9Ovb",
|
||||
"password": "4kWUGkNv",
|
||||
"enabled": False # HTTP代理不支持HTTPS隧道,暂时禁用
|
||||
}, {
|
||||
"name": "天启01",
|
||||
"server": "http://36.137.177.131:50001",
|
||||
"username": "qqwvy0",
|
||||
"password": "mun3r7xz",
|
||||
"enabled": True
|
||||
},
|
||||
{
|
||||
"name": "大麦代理2",
|
||||
"enabled": False
|
||||
}, {
|
||||
"name": "天启02",
|
||||
"server": "http://111.132.40.72:50002",
|
||||
"username": "ih3z07",
|
||||
"password": "078bt7o5",
|
||||
"enabled": True
|
||||
"enabled": False
|
||||
}, {
|
||||
"name": "天启03",
|
||||
"server": "http://210.51.27.194:50001",
|
||||
"username": "hb6su3",
|
||||
"password": "acv2ciow",
|
||||
"enabled": False
|
||||
}
|
||||
]
|
||||
|
||||
@@ -27,18 +66,18 @@ def get_proxy_config(index: int = 0) -> dict:
|
||||
获取指定索引的代理配置
|
||||
|
||||
Args:
|
||||
index: 代理索引(0或1)
|
||||
index: 代理索引(0-4)
|
||||
|
||||
Returns:
|
||||
代理配置字典,包含server、username、password
|
||||
"""
|
||||
if index < 0 or index >= len(DAMAI_PROXY_POOL):
|
||||
raise ValueError(f"代理索引无效: {index},有效范围: 0-{len(DAMAI_PROXY_POOL)-1}")
|
||||
|
||||
proxy = DAMAI_PROXY_POOL[index]
|
||||
if index < 0 or index >= len(PROXY_POOL):
|
||||
raise ValueError(f"代理索引无效: {index},有效范围: 0-{len(PROXY_POOL) - 1}")
|
||||
|
||||
proxy = PROXY_POOL[index]
|
||||
if not proxy.get("enabled", True):
|
||||
raise ValueError(f"代理已禁用: {proxy['name']}")
|
||||
|
||||
|
||||
return {
|
||||
"server": proxy["server"],
|
||||
"username": proxy["username"],
|
||||
@@ -60,7 +99,7 @@ def get_all_enabled_proxies() -> list:
|
||||
"password": p["password"],
|
||||
"name": p["name"]
|
||||
}
|
||||
for p in DAMAI_PROXY_POOL
|
||||
for p in PROXY_POOL
|
||||
if p.get("enabled", True)
|
||||
]
|
||||
|
||||
@@ -73,11 +112,11 @@ def get_random_proxy() -> dict:
|
||||
代理配置字典
|
||||
"""
|
||||
import random
|
||||
enabled_proxies = [p for p in DAMAI_PROXY_POOL if p.get("enabled", True)]
|
||||
|
||||
enabled_proxies = [p for p in PROXY_POOL if p.get("enabled", True)]
|
||||
|
||||
if not enabled_proxies:
|
||||
raise ValueError("没有可用的代理")
|
||||
|
||||
|
||||
proxy = random.choice(enabled_proxies)
|
||||
return {
|
||||
"server": proxy["server"],
|
||||
@@ -87,12 +126,69 @@ def get_random_proxy() -> dict:
|
||||
}
|
||||
|
||||
|
||||
# 快捷访问
|
||||
def format_proxy_url(proxy_config: dict) -> str:
|
||||
"""
|
||||
将代理配置格式化为Playwright可用的代理URL
|
||||
|
||||
Args:
|
||||
proxy_config: 代理配置字典
|
||||
|
||||
Returns:
|
||||
格式化的代理URL: http://username:password@host:port
|
||||
"""
|
||||
server = proxy_config['server'].replace('http://', '').replace('https://', '')
|
||||
username = proxy_config['username']
|
||||
password = proxy_config['password']
|
||||
|
||||
return f"http://{username}:{password}@{server}"
|
||||
|
||||
|
||||
def format_proxy_for_playwright(proxy_config: dict) -> dict:
|
||||
"""
|
||||
将代理配置格式化为Playwright的proxy字典格式
|
||||
|
||||
Args:
|
||||
proxy_config: 代理配置字典
|
||||
|
||||
Returns:
|
||||
Playwright proxy配置: {"server": "...", "username": "...", "password": "..."}
|
||||
"""
|
||||
return {
|
||||
"server": proxy_config['server'],
|
||||
"username": proxy_config['username'],
|
||||
"password": proxy_config['password']
|
||||
}
|
||||
|
||||
|
||||
# 快捷访问函数(保持向后兼容)
|
||||
def get_proxy_1():
|
||||
"""获取代理1配置"""
|
||||
"""获取代理01配置"""
|
||||
return get_proxy_config(0)
|
||||
|
||||
|
||||
def get_proxy_2():
|
||||
"""获取代理2配置"""
|
||||
"""获取代理02配置"""
|
||||
return get_proxy_config(1)
|
||||
|
||||
|
||||
def get_proxy_3():
|
||||
"""获取代理03配置"""
|
||||
return get_proxy_config(2)
|
||||
|
||||
|
||||
def get_proxy_4():
|
||||
"""获取代理04配置"""
|
||||
return get_proxy_config(3)
|
||||
|
||||
|
||||
def get_proxy_5():
|
||||
"""获取代理05配置"""
|
||||
return get_proxy_config(4)
|
||||
|
||||
def get_proxy_6():
|
||||
"""获取代理06配置"""
|
||||
return get_proxy_config(5)
|
||||
|
||||
def get_proxy_7():
|
||||
"""获取代理07配置"""
|
||||
return get_proxy_config(6)
|
||||
|
||||
Reference in New Issue
Block a user