From aa1b608ba6715d7133dc57859e58d538a99a5fbd Mon Sep 17 00:00:00 2001 From: violettools Date: Fri, 23 Jan 2026 13:08:13 +0800 Subject: [PATCH] fix: indentation errors in browser.py, parameter name in mirror.py, update test files --- cfspider/browser.py | 10 +++++----- cfspider/mirror.py | 2 +- test_api.py | 16 +++++++++++----- test_httpx.py | 8 ++++++-- test_impersonate.py | 9 ++++++--- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/cfspider/browser.py b/cfspider/browser.py index 9218769..96be6c6 100644 --- a/cfspider/browser.py +++ b/cfspider/browser.py @@ -176,7 +176,7 @@ class Browser: proxy_url = f"http://127.0.0.1:{port}" else: # 直接使用 HTTP 代理 - proxy_url = cf_proxies + proxy_url = cf_proxies # 3. IP:PORT 格式 elif ':' in cf_proxies and cf_proxies.replace('.', '').replace(':', '').isdigit(): proxy_url = f"http://{cf_proxies}" @@ -187,10 +187,10 @@ class Browser: if uuid: ws_url = f'wss://{hostname}/{uuid}' self._vless_proxy = LocalVlessProxy(ws_url, uuid) - port = self._vless_proxy.start() - proxy_url = f"http://127.0.0.1:{port}" - else: - proxy_url = f"http://{cf_proxies}" + port = self._vless_proxy.start() + proxy_url = f"http://127.0.0.1:{port}" + else: + proxy_url = f"http://{cf_proxies}" def _get_workers_uuid(self, workers_url): """从 Workers 获取 UUID / Get UUID from Workers""" diff --git a/cfspider/mirror.py b/cfspider/mirror.py index 18c051d..90e9d06 100644 --- a/cfspider/mirror.py +++ b/cfspider/mirror.py @@ -179,7 +179,7 @@ class WebMirror: cf_proxies=self.cf_proxies, headless=True, timeout=self.timeout, - vless_uuid=self.vless_uuid + uuid=self.vless_uuid ) return self._browser diff --git a/test_api.py b/test_api.py index 20edaed..d53e5d2 100644 --- a/test_api.py +++ b/test_api.py @@ -1,17 +1,23 @@ -import uuid +# -*- coding: utf-8 -*- +import sys +sys.stdout.reconfigure(encoding='utf-8') + import cfspider +CF_WORKERS = "https://cfspider.violetqqcom.workers.dev" +CF_UUID = "3fde701a-f0c9-45e7-a1b0-b5fe62c4698c" + print("1. 无代理:") r = cfspider.get("https://httpbin.org/ip") print(f" IP: {r.json()['origin']}") print("2. Workers代理 (cf_workers=True):") -r = cfspider.get("https://httpbin.org/ip", cf_proxies="cfspider.violetqqcom.workers.dev") +r = cfspider.get("https://httpbin.org/ip", cf_proxies=CF_WORKERS, uuid=CF_UUID) print(f" IP: {r.json()['origin']}") -print("3. 普通代理 (cf_workers=False):") -r = cfspider.get("https://httpbin.org/ip", cf_proxies="127.0.0.1:9674", cf_workers=False) +print("3. 无代理 HTTP/2:") +r = cfspider.get("https://httpbin.org/ip", http2=True) print(f" IP: {r.json()['origin']}") -cfspider.Browser() + print("\nDone!") diff --git a/test_httpx.py b/test_httpx.py index 31dd2a7..65c57da 100644 --- a/test_httpx.py +++ b/test_httpx.py @@ -1,14 +1,17 @@ +# -*- coding: utf-8 -*- """ 测试 cfspider httpx 异步功能 """ import asyncio import sys +sys.stdout.reconfigure(encoding='utf-8') sys.path.insert(0, '.') import cfspider -# Workers 地址 -CF_WORKERS = "https://ip.kami666.xyz" +# Workers 地址和 UUID +CF_WORKERS = "https://cfspider.violetqqcom.workers.dev" +CF_UUID = "3fde701a-f0c9-45e7-a1b0-b5fe62c4698c" async def test_async_no_proxy(): """测试异步请求 - 无代理""" @@ -175,6 +178,7 @@ def test_sync_http2_workers(): response = cfspider.get( "https://httpbin.org/ip", cf_proxies=CF_WORKERS, + uuid=CF_UUID, http2=True ) print(f"状态码: {response.status_code}") diff --git a/test_impersonate.py b/test_impersonate.py index 7c0cac2..00dbfd8 100644 --- a/test_impersonate.py +++ b/test_impersonate.py @@ -1,13 +1,16 @@ +# -*- coding: utf-8 -*- """ 测试 cfspider TLS 指纹模拟功能 """ import sys +sys.stdout.reconfigure(encoding='utf-8') sys.path.insert(0, '.') import cfspider -# Workers 地址 -CF_WORKERS = "https://ip.kami666.xyz" +# Workers 地址和 UUID +CF_WORKERS = "https://cfspider.violetqqcom.workers.dev" +CF_UUID = "3fde701a-f0c9-45e7-a1b0-b5fe62c4698c" def test_impersonate_get(): @@ -80,7 +83,7 @@ def test_impersonate_firefox(): def test_impersonate_workers(): """测试 TLS 指纹 + Workers 代理""" print("\n" + "="*60) - print("测试 4: TLS 指纹 + Workers 代理") + print("测试 4: TLS 指纹 + Workers 代理 (使用 /proxy API)") print("="*60) try: