From 6b6d927630d034bca59935057d26fc5b573b44e0 Mon Sep 17 00:00:00 2001 From: work Date: Mon, 9 Feb 2026 17:01:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BB=A3=E7=90=86=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=B0=9D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spider/proxy_valid.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/spider/proxy_valid.py b/spider/proxy_valid.py index bd81da0..dd7c137 100644 --- a/spider/proxy_valid.py +++ b/spider/proxy_valid.py @@ -14,7 +14,6 @@ class ProxyChecker: api_url: 获取代理的API地址 timeout: 请求超时时间(秒) """ - self.api_url = "http://api.proxy.ip2world.com/getProxyIp?num=100®ions=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}")