使用 Firecrawl 进行基础抓取
/scrape
端点。
抓取 PDF
parsers
选项(例如 parsers: ["pdf"]
)。
抓取选项
/scrape
端点时,你可以通过以下选项定制抓取。
格式(formats
)
- 类型:
array
- 字符串:
["markdown", "links", "html", "rawHtml", "summary"]
- 对象格式:
- JSON:
{ type: "json", prompt, schema }
- 截图:
{ type: "screenshot", fullPage?, quality?, viewport? }
- 变更跟踪:
{ type: "changeTracking", modes?, prompt?, schema?, tag? }
(需搭配markdown
)
- JSON:
- 默认值:
["markdown"]
全页内容 vs 主内容(onlyMainContent
)
- 类型:
boolean
- 描述: 默认仅返回主内容。将其设为
false
可返回全页内容。 - 默认值:
true
- 类型:
array
- 描述: 抓取时要包含的 HTML 标签/类名/ID。
- 类型:
array
- 描述: 在抓取时需要排除的 HTML 标签/类名/ID。
等待页面就绪(waitFor
)
- 类型:
integer
- 描述: 抓取前等待的毫秒数(请谨慎使用)。
- 默认值:
0
新鲜度与缓存(maxAge
)
- 类型:
integer
(毫秒) - 描述: 如果页面的缓存版本在
maxAge
内仍然有效,Firecrawl 会立即返回;否则将抓取最新内容并更新缓存。将其设为0
可始终获取最新内容。 - 默认值:
172800000
(2 天)
请求超时(timeout
)
- 类型:
integer
- 描述: 在中止前的最长时长(毫秒)。
- 默认值:
30000
(30 秒)
PDF 解析(parsers
)
- 类型:
array
- 描述: 用于控制解析行为。要解析 PDF,请设置
parsers: ["pdf"]
。
Actions (actions
)
- Type:
array
- Description: 抓取前执行的一系列浏览器步骤。
- Supported actions:
wait
{ milliseconds }
click
{ selector }
write
{ selector, text }
press
{ key }
scroll
{ direction: "up" | "down" }
scrape
{ selector }
(抓取子元素)executeJavascript
{ script }
pdf
(在部分流程中触发 PDF 渲染)
示例用法
cURL
- 以 Markdown 返回完整页面内容。
- 在响应中包含 Markdown、原始 HTML、HTML、链接以及截图。
- 仅包含 HTML 标签
<h1>
、<p>
、<a>
,以及类名为.main-content
的元素,同时排除任何 ID 为#ad
和#footer
的元素。 - 在开始抓取前等待 1000 毫秒(1 秒),以便页面加载。
- 将抓取请求的最长持续时间设置为 15000 毫秒(15 秒)。
- 通过
parsers: ["pdf"]
显式解析 PDF。
通过格式进行 JSON 提取
formats
中使用 JSON 格式对象,一次完成结构化数据的提取:
/extract 端点
抓取多个页面
/v2/crawl
端点。
cURL
检查爬取任务
cURL
分页/下一页 URL
next
参数,即指向下一页结果的 URL。
爬取提示与参数预览
prompt
,让 Firecrawl 自动推导爬取设置。请先预览结果:
cURL
爬虫选项
/v2/crawl
端点时,可以通过以下方式自定义爬取行为:
includePaths
- 类型:
array
- 说明: 要包含的正则表达式模式。
- 示例:
["^/blog/.*$", "^/docs/.*$"]
excludePaths
- 类型:
array
- 描述: 用于排除的正则表达式模式。
- 示例:
["^/admin/.*$", "^/private/.*$"]
maxDiscoveryDepth
- 类型:
integer
- 描述: 查找新 URL 的最大发现深度。
limit
- 类型:
integer
- 描述: 爬取的最大页面数量。
- 默认值:
10000
crawlEntireDomain
- 类型:
boolean
- 描述: 跨同级/父级页面扩展爬取以覆盖整个域名。
- 默认值:
false
allowExternalLinks
- 类型:
boolean
- 描述: 跟随指向外部域名的链接。
- 默认值:
false
allowSubdomains
- 类型:
boolean
- 描述: 允许跟踪主域的子域名。
- 默认值:
false
delay
- Type:
number
- Description: 每次抓取之间的延迟(单位:秒)。
- Default:
undefined
scrapeOptions
- 类型:
object
- 描述: 抓取器选项(参见上面的 格式)。
- 示例:
{ "formats": ["markdown", "links", {"type": "screenshot", "fullPage": true}], "includeTags": ["h1", "p", "a", ".main-content"], "excludeTags": ["#ad", "#footer"], "onlyMainContent": false, "waitFor": 1000, "timeout": 15000}
- 默认值:
formats: ["markdown"]
,默认启用缓存(maxAge 约 2 天)
示例用法
cURL
映射网站链接
/v2/map
端点用于识别与指定网站相关的 URL。
使用方法
cURL
Map 选项
search
- 类型:
string
- 描述: 过滤包含指定文本的链接。
limit
- 类型:
integer
- 描述: 返回的链接数量最大值。
- 默认值:
100
sitemap
- 类型:
"only" | "include" | "skip"
- 描述: 控制在映射时对 sitemap 的使用。
- 默认值:
"include"
includeSubdomains
- 类型:
boolean
- 说明: 是否包含该网站的子域名。
- 默认值:
true