更改代理进行尝试

This commit is contained in:
work
2026-02-09 17:01:06 +08:00
parent 7ecfc5b376
commit 6b6d927630

View File

@@ -14,7 +14,6 @@ class ProxyChecker:
api_url: 获取代理的API地址
timeout: 请求超时时间(秒)
"""
self.api_url = "http://api.proxy.ip2world.com/getProxyIp?num=100&regions=us&lb=1&return_type=json&protocol=http"
self.timeout = timeout
def get_proxies_from_api(self) -> list:
@@ -25,15 +24,36 @@ class ProxyChecker:
list: 代理列表,格式为 [{"ip": "x.x.x.x", "port": xxxx}, ...]
"""
try:
response = requests.get(self.api_url, timeout=self.timeout)
pconfig = {
'proxyUser': 'qwkpslims6im',
'proxyPass': 'z6wM0LnETJG3d3RN',
'proxyHost': 'us.911proxy.net',
'proxyPort': '2600'
}
url = "https://api.ip.cc/"
proxies = {
"http": "http://{}:{}@{}:{}".format(pconfig['proxyUser'], pconfig['proxyPass'], pconfig['proxyHost'],
pconfig['proxyPort']),
"https": "http://{}:{}@{}:{}".format(pconfig['proxyUser'], pconfig['proxyPass'], pconfig['proxyHost'],
pconfig['proxyPort'])
}
response = requests.get(url=url, proxies=proxies, timeout=self.timeout)
response.raise_for_status()
data = response.json()
if data.get("code") == 0 and data.get("success"):
return data.get("data", [])
else:
print(f"API返回错误: {data.get('msg')}")
return []
# {'http': 'http://qwkpslims6im:z6wM0LnETJG3d3RN@us.911proxy.net:2600',
# 'https': 'http://qwkpslims6im:z6wM0LnETJG3d3RN@us.911proxy.net:2600'}
# {"ip": "176.117.106.153", "country_code": "TR", "city": "", "country": "Turkey", "province": "Istanbul",
# "zip_code": "34122", "timezone": "Europe/Istanbul", "latitude": 41.0082, "longitude": 28.9784,
# "asn": "AS202561", "asn_name": "High Speed Telekomunikasyon ve Hab. Hiz. Ltd. Sti.",
# "asn_type": "business"}
proxy_url = data['http']
scheme, rest = proxy_url.split("://")
auth_hostport = rest.split("@")[1]
host, port = auth_hostport.split(":")
return [{"ip": host, "port": port}]
except requests.exceptions.RequestException as e:
print(f"获取代理失败: {e}")