Firecrawl 能帮你将整个网站转换为适合 LLM 使用的 Markdown 格式
欢迎使用 Firecrawl
Firecrawl 是一个 API 服务,只需提供 URL 即可自动爬取并转换为干净 Markdown。我们会爬取所有可访问的子页面,为每个页面生成整洁的 Markdown。无需站点地图。
如何使用?
我们为托管版本提供了易用的 API。你可以在这里找到 Playground 和文档。如果需要,也可以自行托管后端。
API 密钥
使用 API 前需要在 Firecrawl 上注册并获取 API 密钥
核心功能
• 抓取:抓取单个 URL 并转换为 LLM 可用格式(Markdown、通过 LLM 抽取的结构化数据、截图、HTML) • 爬取:爬取网页所有 URL 并返回结构化的内容 • 地图:输入网站即可极速获取所有 URL • 抽取:通过 AI 从单页面、多页面或整站提取结构化数据
强大能力
• LLM 就绪格式:Markdown、结构化数据、截图、HTML、链接、元数据 • 复杂场景处理:代理、反爬机制、动态内容(JS 渲染)、输出解析、流程编排 • 高度可定制:可排除指定标签、带自定义头信息爬取权限内容、设置最大爬取深度等 • 多媒体解析:支持 PDF、docx 和图片 • 可靠优先:设计目标就是确保数据获取,无论多难 • 交互动作:点击、滚动、输入、等待等预操作支持
完整功能说明请查看 文档
爬取功能
用于爬取 URL 及其所有可访问子页面。提交爬取任务后会返回用于查询状态的 job ID
安装
Python
Node
Go
Rust
Copy
pip install firecrawl-py
使用示例
Python
Node
Go
Rust
cURL
Copy
from firecrawl import FirecrawlApp
app = FirecrawlApp(api_key="fc-YOUR_API_KEY")
# 爬取网站:
crawl_status = app.crawl_url(
'https://firecrawl.dev',
params={
'limit': 100,
'scrapeOptions': {'formats': ['markdown', 'html']}
},
poll_interval=30
)
print(crawl_status)
如果使用 cURL 或 SDK 的异步爬取功能,会返回用于查询爬取状态的 ID
Copy
{
"success": true,
"id": "123-456-789",
"url": "https://api.firecrawl.dev/v1/crawl/123-456-789"
}
查询爬取状态
用于查询爬取作业状态并获取结果
Python
Node
Go
Rust
cURL
Copy
crawl_status = app.check_crawl_status("<crawl_id>")
print(crawl_status)
响应内容
响应内容视爬取状态而异。当任务未完成或数据超过 10MB 时,会返回 next
参数用于获取后续数据。若没有 next
参数则表示数据已全部返回
爬取中
已完成
Copy
{
"status": "scraping",
"total": 36,
"completed": 10,
"creditsUsed": 10,
"expiresAt": "2024-00-00T00:00:00.000Z",
"next": "https://api.firecrawl.dev/v1/crawl/123-456-789?skip=10",
"data": [
{
"markdown": "[Firecrawl Docs 首页!...",
"html": "<!DOCTYPE html><html lang=\"en\" class=\"js-focus-visible lg:[--scroll-mt:9.5rem]\" data-js-focus-visible=\"\">...",
"metadata": {
"title": "使用 Groq Llama 3 搭建「网站对话」应用 | Firecrawl",
"language": "en",
"sourceURL": "https://docs.firecrawl.dev/learn/rag-llama3",
"description": "学习如何使用 Firecrawl、Groq Llama 3 和 Langchain 搭建「与网站对话」机器人",
"ogLocaleAlternate": [],
"statusCode": 200
}
},
...
]
}
内容抓取
使用 scrape_url
方法抓取单个 URL 内容,返回字典格式数据
Python
Node
Go
Rust
cURL
Copy
from firecrawl import FirecrawlApp
app = FirecrawlApp(api_key="fc-YOUR_API_KEY")
# 抓取网站:
scrape_result = app.scrape_url('firecrawl.dev', params={'formats': ['markdown', 'html']})
print(scrape_result)
响应示例
SDKs 会直接返回数据对象,cURL 返回原始 json 内容
Copy
{
"success": true,
"data" : {
"markdown": "Launch Week I 启动中[💥 免费获得 2 个月使用权...",
"html": "<!DOCTYPE html><html lang=\"en\" class=\"light\" style=\"color-scheme: light;\"><body class=\"__variable_36bd41 __variable_d7dc5d font-inter ...",
"metadata": {
"title": "主页 - Firecrawl",
"description": "Firecrawl 可将任何网站转换为干净 Markdown",
"language": "en",
"keywords": "Firecrawl,Markdown,数据,Mendable,Langchain",
"robots": "follow, index",
"ogTitle": "Firecrawl",
"ogDescription": "将任何网站转为 LLM 可用的结构化数据",
"ogUrl": "https://www.firecrawl.dev/",
"ogImage": "https://www.firecrawl.dev/og.png?123",
"ogLocaleAlternate": [],
"ogSiteName": "Firecrawl",
"sourceURL": "https://firecrawl.dev",
"statusCode": 200
}
}
}
数据抽取
通过 LLM 抽取功能,可以从任意 URL 轻松提取结构化数据。我们支持 pydantic 格式校验,使用示例如下:
目前 v1 版本仅在 node、python 和 cURL 可用
Python
Node
cURL
Copy
from firecrawl import FirecrawlApp
from pydantic import BaseModel, Field
# 用 API 密钥初始化
app = FirecrawlApp(api_key='your_api_key')
class ExtractSchema(BaseModel):
company_mission: str
supports_sso: bool
is_open_source: bool
is_in_yc: bool
data = app.scrape_url('https://docs.firecrawl.dev/', {
'formats': ['json'],
'jsonOptions': {
'schema': ExtractSchema.model_json_schema(),
}
})
print(data["json"])
输出示例:
JSON
Copy
{
"success": true,
"data": {
"json": {
"company_mission": "开发基于技术文档的安全 AI 问答系统,减轻团队负担",
"supports_sso": true,
"is_open_source": false,
"is_in_yc": true
},
"metadata": {
"title": "Mendable",
"description": "Mendable 让你轻松构建 AI 聊天应用。一站式完成数据摄入、定制化与部署。由 SideGuide 出品",
"robots": "follow, index",
"ogTitle": "Mendable",
"ogDescription": "Mendable 让你轻松构建 AI 聊天应用。一站式完成数据摄入、定制化与部署。由 SideGuide 出品",
"ogUrl": "https://docs.firecrawl.dev/",
"ogImage": "https://docs.firecrawl.dev/mendable_new_og1.png",
"ogLocaleAlternate": [],
"ogSiteName": "Mendable",
"sourceURL": "https://docs.firecrawl.dev/"
},
}
}
无预设结构的抽取(新增功能)
现在可以通过输入 prompt
让 LLM 自主决定数据结构
cURL
Copy
curl -X POST https://api.firecrawl.dev/v1/scrape \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"url": "https://docs.firecrawl.dev/",
"formats": ["json"],
"jsonOptions": {
"prompt": "从页面提取公司使命声明"
}
}'
输出示例:
JSON
Copy
{
"success": true,
"data": {
"json": {
"company_mission": "开发基于技术文档的安全 AI 问答系统,减轻团队负担"
},
"metadata": {
"title": "Mendable",
"description": "Mendable 让你轻松构建 AI 聊天应用。一站式完成数据摄入、定制化与部署。由 SideGuide 出品",
"robots": "follow, index",
"ogTitle": "Mendable",
"ogDescription": "Mendable 让你轻松构建 AI 聊天应用。一站式完成数据摄入、定制化与部署。由 SideGuide 出品",
"ogUrl": "https://docs.firecrawl.dev/",
"ogImage": "https://docs.firecrawl.dev/mendable_new_og1.png",
"ogLocaleAlternate": [],
"ogSiteName": "Mendable",
"sourceURL": "https://docs.firecrawl.dev/"
},
}
}
抽取功能(v0 版本)
Python
JavaScript
Go
Rust
cURL
Copy
app = FirecrawlApp(version="v0")
class ArticleSchema(BaseModel):
title: str
points: int
by: str
commentsURL: str
class TopArticlesSchema(BaseModel):
top: List[ArticleSchema] = Field(..., max_items=5, description="前 5 热门故事")
data = app.scrape_url('https://news.ycombinator.com', {
'extractorOptions': {
'extractionSchema': TopArticlesSchema.model_json_schema(),
'mode': 'llm-extraction'
},
'pageOptions':{
'onlyMainContent': True
}
})
print(data["llm_extraction"])
网页交互动作
Firecrawl 允许在抓取前对网页执行各类交互操作,这对处理动态内容、页面跳转或需要用户交互的场景非常有用。
以下示例展示了如何通过动作实现:访问 google.com -> 搜索 Firecrawl -> 点击第一条结果 -> 截图。建议在动作前后使用 wait
操作确保页面加载完成。
示例
Python
from firecrawl import FirecrawlApp
app = FirecrawlApp(api_key="fc-YOUR_API_KEY")
# 带交互抓取:
scrape_result = app.scrape_url('firecrawl.dev',
params={
'formats': ['markdown', 'html'],
'actions': [
{"type": "wait", "milliseconds": 2000},
{"type": "click", "selector": "textarea[title=\"Search\"]"},
{"type": "wait", "milliseconds": 2000},
{"type": "write", "text": "firecrawl"},
{"type": "wait", "milliseconds": 2000},
{"type": "press", "key": "ENTER"},
{"type": "wait", "milliseconds": 3000},
{"type": "click", "selector": "h3"},
{"type": "wait", "milliseconds": 3000},
{"type": "scrape"},
{"type": "screenshot"}
]
}
)
print(scrape_result)
输出结果
JSON
Copy
{
"success": true,
"data": {
"markdown": "Our first Launch Week is over! [See the recap 🚀](blog/firecrawl-launch-week-1-recap)...",
"actions": {
"screenshots": [
"https://alttmdsdujxrfnakrkyi.supabase.co/storage/v1/object/public/media/screenshot-75ef2d87-31e0-4349-a478-fb432a29e241.png"
],
"scrapes": [
{
"url": "https://www.firecrawl.dev/",
"html": "<html><body><h1>Firecrawl</h1></body></html>"
}
]
},
"metadata": {
"title": "Home - Firecrawl",
"description": "Firecrawl crawls and converts any website into clean markdown.",
"language": "en",
"keywords": "Firecrawl,Markdown,Data,Mendable,Langchain",
"robots": "follow, index",
"ogTitle": "Firecrawl",
"ogDescription": "Turn any website into LLM-ready data.",
"ogUrl": "https://www.firecrawl.dev/",
"ogImage": "https://www.firecrawl.dev/og.png?123",
"ogLocaleAlternate": [],
"ogSiteName": "Firecrawl",
"sourceURL": "http://google.com",
"statusCode": 200
}
}
}
开源版 vs 云版
功能 | 开源版 | 云版 |
---|---|---|
核心抓取 | ✅ | ✅ |
爬虫 | ✅ | ✅ |
自动 JS 渲染 | ❌ | ✅ |
PDF/图像解析 | ❌ | ✅ |
交互动作 | ❌ | ✅ |
企业级许可 | ❌ | ✅ |
托管代理池 | ❌ | ✅ |
优先级支持 | ❌ | ✅ |