批量网页抓取 API
一次调用最多发送 10,000 个 URL。每个页面都以干净的数据返回。
提交 URL
batch.py
import 请求job = 请求.post( "https://api.spicrawl.com/v1/batch", headers="Authorization": "Bearer spicrawl_live_…", json={ "urls": ["https://example.com/one", "https://example.com/two"], "js_render": True, },).json()# Poll GET /v1/batch/{id} until status is "completed"print(job["id"], job["total_items"])工作原理
- 发送你的 URL 到
POST /v1/batch。你会立即得到一个任务 ID。 - 检查任务 直到其状态为
completed、failed或cancelled。 - 读取结果 以 JSON Lines 格式逐页读取,并附带
X-Next-Cursor。
curl https://api.spicrawl.com/v1/batch \
-H "Authorization: Bearer $SPICRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "catalog-refresh",
"urls": ["https://example.com/products/1", "https://example.com/products/2"],
"response_format": "markdown"
}'import os, time, requests
API = "https://api.spicrawl.com"
H = {"Authorization": f"Bearer {os.environ['SPICRAWL_API_KEY']}"}
job = requests.post(f"{API}/v1/batch", headers=H, json={
"urls": ["https://example.com/products/1", "https://example.com/products/2"],
"response_format": "markdown",
}, timeout=60).json()
while job["status"] not in ("completed", "failed", "cancelled"):
time.sleep(5)
job = requests.get(f"{API}/v1/batch/{job['id']}", headers=H, timeout=30).json()
results = requests.get(f"{API}/v1/batch/{job['id']}/results", headers=H, timeout=120)
print(results.text) # JSON Lines: one result per linespicrawl batch submit urls.txt --format markdown --wait
spicrawl batch results <job-id> --all -o results.jsonl把 key 保存在 SPICRAWL_API_KEY 中。你的 key 需要 batch 权限范围。
每个条目能做什么
- 格式:
html(默认)、markdown、text或json。 - 清理:
main_content_only、include_tags和exclude_tags适用于 Markdown 和文本。 - JavaScript: 对需要浏览器的页面设置
js_render: true。 - 按 URL 的设置: 发送
items而不是urls,即可为每个 URL 单独设置,并附带一个external_id。
须知
- 批量不支持: 提取、截图、浏览器操作和会话。请求这些功能的任务会在收费之前被拒绝并返回 400。这类页面请使用 单次抓取。
- 结果过期 任务完成后 72 小时。
- 不支持爬取。 Spicrawl 不会查找 URL 或跟随链接。列表由你发送。
- 定价: 公测期间免费。每个成功的条目消耗的积分与单次抓取相同。
常见问题
一个批量任务最多可以有多少个 URL?
每次调用最多 10,000 个 URL。以列表形式放在 urls 中发送,或在每个 URL 需要自己的设置或可用于匹配的 external_id 时,以 items 形式发送。
批量任务返回什么格式?
每一项都以 html(默认)、markdown、text 或 json 返回。Markdown 和 text 使用与单次抓取相同的转换。
批量结果保留多久?
For 72 hours after the job finishes. Read them with GET /v1/batch/{id}/results, which returns JSON Lines one page at a time.
批量任务可以提取字段或点击按钮吗?
不能。提取、截图、浏览器操作和会话不能在批量中运行。请求这些功能的任务会在计费前被拒绝并返回 400。这些页面请使用单次抓取。
批量任务会爬取网站吗?
不能。Spicrawl 不会查找 URL,也不会跟随链接。你需要自己发送想要的 URL 列表。