mirror of
https://github.com/violettoolssite/CFspider.git
synced 2026-04-04 18:59:02 +08:00
fix: indentation errors in browser.py, parameter name in mirror.py, update test files
This commit is contained in:
@@ -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"""
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
16
test_api.py
16
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!")
|
||||
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user