欢迎使用 CFspider API 文档

CFspider 是一个强大的 Cloudflare 代理 IP 池 Python 库,提供完整的 HTTP 请求、数据提取、反爬虫规避等功能。

安装

使用 pip 安装 CFspider:

bash
pip install cfspider

可选依赖

根据需要使用,安装对应的可选依赖组:

bash
# 浏览器模式支持
pip install cfspider[browser]

# 数据提取支持(XPath, JSONPath)
pip install cfspider[extract]

# 进度条显示
pip install cfspider[progress]

# Excel 导出支持
pip install cfspider[excel]

# 安装所有可选依赖
pip install cfspider[all]

快速开始

基本 GET 请求

python
import cfspider

# 直接请求
response = cfspider.get("https://httpbin.org/ip")
print(response.json())

# 使用 Workers 代理
response = cfspider.get(
    "https://httpbin.org/ip",
    cf_proxies="https://your-workers.dev"
)
print(response.cf_colo)  # Cloudflare 节点代码

数据提取

python
import cfspider

response = cfspider.get("https://example.com")

# CSS 选择器
title = response.find("h1")
links = response.find_all("a", attr="href")

# 批量提取
data = response.pick(
    title="h1",
    links=("a", "href")
)
data.save("output.json")

批量请求

python
import cfspider

urls = [
    "https://example.com/page1",
    "https://example.com/page2",
    "https://example.com/page3"
]

results = cfspider.batch(
    urls,
    pick={"title": "h1"},
    concurrency=5
)

results.save("results.csv")

主要功能模块

同步 HTTP 请求

支持 GET、POST、PUT、DELETE 等所有 HTTP 方法,兼容 requests 库语法。

查看文档 →

异步 HTTP 请求

基于 httpx 的异步请求,支持 HTTP/2 协议和流式响应。

查看文档 →

数据提取

支持 CSS 选择器、XPath、JSONPath 三种方式提取数据。

查看文档 →

批量请求

并发批量请求多个 URL,支持进度显示和结果聚合。

查看文档 →

隐身模式

自动添加完整浏览器请求头,模拟真实浏览器访问。

查看文档 →

TLS 指纹模拟

模拟真实浏览器的 TLS 握手特征,支持 25+ 种浏览器指纹。

查看文档 →