Cloudflare Workers proxy IP pool client
Project description
CFspider
基于 Cloudflare Workers 的代理 IP 池,使用 Cloudflare 全球边缘节点 IP 作为代理出口。
特性
- 使用 Cloudflare 全球 300+ 边缘节点 IP
- 与 requests 库语法一致,无学习成本
- 支持 GET、POST、PUT、DELETE 等所有 HTTP 方法
- 支持 Session 会话管理
- 返回 Cloudflare 节点信息(cf_colo、cf_ray)
- 完全免费,Workers 免费版每日 100,000 请求
部署 Workers
步骤 1:创建 Worker
- 登录 Cloudflare Dashboard
- 进入 Workers & Pages
- 点击 Create application → Create Worker
- 将
workers.js代码粘贴到编辑器中 - 点击 Deploy
步骤 2:创建 KV 命名空间
- 进入 Workers & Pages → KV
- 点击 Create a namespace
- 输入名称(如
cfspider) - 创建后复制 Namespace ID
步骤 3:绑定 KV
- 进入你的 Worker → Settings → Variables
- 在 KV Namespace Bindings 中添加:
- Variable name:
KV - KV namespace: 选择刚创建的命名空间
- Variable name:
- 点击 Save
步骤 4:设置环境变量(可选)
在 Worker Settings → Variables → Environment Variables 中添加:
| 变量名 | 说明 | 示例 |
|---|---|---|
| ADMIN | 管理密码 | your_password |
| UUID | 自定义 UUID | 留空则自动生成 |
| PROXYIP | 反代 IP | proxyip.example.com |
步骤 5:绑定自定义域名(可选)
- 进入 Worker → Settings → Triggers
- 添加 Custom Domain
- 输入你的域名(需已托管在 Cloudflare)
安装
pip install cfspider
快速开始
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.get("https://httpbin.org/ip", cf_proxies=cf_proxies)
print(response.text)
API 参考
请求方法
CFspider 支持以下 HTTP 方法,语法与 requests 库一致:
import cfspider
cf_proxies = "https://your-workers.dev"
cfspider.get(url, cf_proxies=cf_proxies)
cfspider.post(url, cf_proxies=cf_proxies, json=data)
cfspider.put(url, cf_proxies=cf_proxies, data=data)
cfspider.delete(url, cf_proxies=cf_proxies)
cfspider.head(url, cf_proxies=cf_proxies)
cfspider.options(url, cf_proxies=cf_proxies)
cfspider.patch(url, cf_proxies=cf_proxies, json=data)
请求参数
| 参数 | 类型 | 说明 |
|---|---|---|
| url | str | 目标 URL |
| cf_proxies | str | Workers 地址(必填) |
| params | dict | URL 查询参数 |
| data | dict/str | 表单数据 |
| json | dict | JSON 数据 |
| headers | dict | 请求头 |
| cookies | dict | Cookies |
| timeout | int/float | 超时时间(秒) |
响应对象
| 属性 | 类型 | 说明 |
|---|---|---|
| text | str | 响应文本 |
| content | bytes | 响应字节 |
| json() | dict | 解析 JSON |
| status_code | int | HTTP 状态码 |
| headers | dict | 响应头 |
| cf_colo | str | Cloudflare 节点代码(如 NRT) |
| cf_ray | str | Cloudflare Ray ID |
使用示例
GET 请求
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.get(
"https://httpbin.org/get",
cf_proxies=cf_proxies,
params={"key": "value"}
)
print(response.status_code)
print(response.json())
POST 请求
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.post(
"https://httpbin.org/post",
cf_proxies=cf_proxies,
json={"name": "cfspider", "version": "1.0"}
)
print(response.json())
使用 Session
Session 可以复用 Workers 地址,无需每次请求都指定:
import cfspider
cf_proxies = "https://your-workers.dev"
session = cfspider.Session(cf_proxies=cf_proxies)
r1 = session.get("https://httpbin.org/ip")
r2 = session.post("https://httpbin.org/post", json={"test": 1})
r3 = session.get("https://example.com")
print(r1.text)
print(r2.json())
session.close()
获取 Cloudflare 节点信息
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.get("https://httpbin.org/ip", cf_proxies=cf_proxies)
print(f"出口 IP: {response.json()['origin']}")
print(f"节点代码: {response.cf_colo}")
print(f"Ray ID: {response.cf_ray}")
自定义请求头
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.get(
"https://httpbin.org/headers",
cf_proxies=cf_proxies,
headers={
"User-Agent": "MyApp/1.0",
"Accept-Language": "zh-CN"
}
)
print(response.json())
设置超时
import cfspider
cf_proxies = "https://your-workers.dev"
response = cfspider.get(
"https://httpbin.org/delay/5",
cf_proxies=cf_proxies,
timeout=10
)
错误处理
import cfspider
cf_proxies = "https://your-workers.dev"
try:
response = cfspider.get("https://httpbin.org/ip", cf_proxies=cf_proxies)
response.raise_for_status()
print(response.text)
except cfspider.CFSpiderError as e:
print(f"请求失败: {e}")
except Exception as e:
print(f"其他错误: {e}")
注意事项
- Workers 免费版限制:每日 100,000 请求,单次 CPU 时间 10ms
- 请求体大小限制:免费版 100MB,付费版无限制
- 超时限制:免费版 30 秒,付费版无限制
- 不支持 WebSocket、gRPC 等非 HTTP 协议
License
MIT License
链接
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cfspider-1.0.1.tar.gz
(6.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfspider-1.0.1.tar.gz.
File metadata
- Download URL: cfspider-1.0.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15f93bf37f1d2500f8e00edf2883dbac5f34be53bf8750b5535f426a4aa96b80
|
|
| MD5 |
c735e71d292d087f066c44da1f103aaa
|
|
| BLAKE2b-256 |
6466d3103bdfb1fcef8af01d72587ddb208f2d436efadc6a2c8e10abbbcc09ca
|
File details
Details for the file cfspider-1.0.1-py3-none-any.whl.
File metadata
- Download URL: cfspider-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b23e0ab6976ff60655f80164af95567690f5d21a87da3ac23780e42e16fae2f
|
|
| MD5 |
8375d511c57df6895f04286d234bd6f6
|
|
| BLAKE2b-256 |
40b6f280750ab15557fe8c1cade3e4212f8273c39b2abc9fe95e209ad558f78a
|