欢迎使用 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")