使用 Cloudflare Browser Rendering API 抓取网站。适用于需要爬取整个站点、构建知识库、从多页面提取内容等。
Crawl entire websites using Cloudflare's Browser Rendering /crawl API. Async job-based crawling with JS rendering.
Get Cloudflare API credentials:
Account.Browser Rendering permissionSet environment variables:
bash
export CLOUDFLARE_API_TOKEN="your_token"
export CLOUDFLARE_ACCOUNT_ID="your_account_id"
bash
# Start a crawl job
node scripts/crawl.js start https://example.com --limit 50
# Check status
node scripts/crawl.js status <job_id>
# Get results as markdown
node scripts/crawl.js results <job_id> --format markdown
bash
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/browser-rendering/crawl" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"limit": 50,
"depth": 3,
"formats": ["markdown"]
}'
Returns: { "success": true, "result": "job_id_here" }
bash
curl "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/browser-rendering/crawl/$JOB_ID?limit=1" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Status values: running, completed, errored, cancelled_due_to_timeout
bash
curl "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/browser-rendering/crawl/$JOB_ID" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
ParameterTypeDefaultDescriptionurlstringrequiredStarting URLlimitnumber10Max pages to crawl (max 100,000)depthnumber100000Max link depth from start URLsourcestring"all"URL discovery: all, sitemaps, linksformatsarray["html"]Output: html, markdown, jsonrenderbooleantrueExecute JS (false = fast HTML only)
json
{
"url": "https://example.com/page",
"status": "completed",
"markdown": "# Page Title\n\nContent here...",
"metadata": { "title": "Page Title", "status": 200 }
}
Uses Workers AI to extract structured data. Requires jsonOptions.prompt:
json
{
"formats": ["json"],
"jsonOptions": {
"prompt": "Extract product name, price, and description"
}
}
PlanFree TierOverageWorkers Free10 min/dayN/AWorkers Paid10 hrs/month$0.09/hour
javascript
// Crawl docs site for knowledge base
const job = await startCrawl({
url: 'https://docs.example.com',
limit: 500,
formats: ['markdown'],
source: 'sitemaps' // Use sitemap for efficiency
});
// Wait for completion
const results = await waitForCrawl(job.id);
// Save markdown files for RAG
for (const page of results.records) {
if (page.status === 'completed') {
fs.writeFileSync(`docs/${slugify(page.url)}.md`, page.markdown);
}
}
Use CaseCloudflare CrawlBrowserbaseFull site scrape✅ Best❌ ManualInteractive (forms)❌ No✅ BestCF-protected sites✅ Native⚠️ Cloud bypassAI extraction✅ Built-in✅ StagehandSession management✅ Async jobs❌ ManualCost$0.09/hrCredits
Use Cloudflare Crawl for bulk content extraction. Use Browserbase for interactive automation.