链载Ai

标题: Firecrawl深度之基础刨析篇 [打印本页]

作者: 链载Ai    时间: 昨天 17:56
标题: Firecrawl深度之基础刨析篇

一、Firecrawl是什么

Firecrawl是一个云爬取服务,可以无需网站地图的情况下爬取整个网站内容、单个网页、网站地图;通过内置LLM实现自然语言对爬取内容的抽取。同时,Firecrawl也有对应的开源版本,可以自行下载开源代码并运行。

二、Firecrawl主要功能(以Cloud服务讲解)

2.1 Scrape 爬取单个url

将任何 URL 转换为干净数据

Firecrawl 将网页转换为 markdown,非常适合 LLM 应用程序。

它管理复杂性:代理、缓存、速率限制、js 阻止的内容 处理动态内容:动态网站、js 渲染的网站、PDF、图像 输出干净的 markdown、结构化数据、屏幕截图或 html。 调用端点如下:

curl --request POST \
--url https://host:port/v1/scrape \
--header'Content-Type: application/json'\
--data'{
"url": "<string>",
"formats": [
"markdown"
],
"onlyMainContent": true,
"includeTags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"headers": {},
"waitFor": 0,
"mobile": false,
"skipTlsVerification": false,
"timeout": 30000,
"jsonOptions": {
"schema": {},
"systemPrompt": "<string>",
"prompt": "<string>"
},
"actions": [
{
"type": "wait",
"milliseconds": 2,
"selector": "#my-element"
}
],
"location": {
"country": "US",
"languages": [
"en-US"
]
},
"removeBase64Images": true,
"blockAds": true,
"proxy": "basic"
}'

2.2 Scrape 批量爬取多个url

可以同时批量抓取多个 URL。它以起始 URL 和可选参数作为参数。params 参数允许您为批量抓取作业指定其他选项,例如输出格式。

它的工作方式与端点非常相似/crawl。它提交批量抓取作业并返回作业 ID 以检查批量抓取的状态。

SDK 提供两种方法:同步和异步。同步方法将返回批量抓取作业的结果,而异步方法将返回一个作业 ID,您可以使用该 ID 检查批量抓取的状态。

curl --request POST \
--url https://host:port/v1/batch/scrape \
--header'Content-Type: application/json'\
--data'{
"urls": [
"<string>"
],
"webhook": {
"url": "<string>",
"headers": {},
"metadata": {},
"events": [
"completed"
]
},
"ignoreInvalidURLs": false,
"formats": [
"markdown"
],
"onlyMainContent": true,
"includeTags": [
"<string>"
],
"excludeTags": [
"<string>"
],
"headers": {},
"waitFor": 0,
"mobile": false,
"skipTlsVerification": false,
"timeout": 30000,
"jsonOptions": {
"schema": {},
"systemPrompt": "<string>",
"prompt": "<string>"
},
"actions": [
{
"type": "wait",
"milliseconds": 2,
"selector": "#my-element"
}
],
"location": {
"country": "US",
"languages": [
"en-US"
]
},
"removeBase64Images": true,
"blockAds": true,
"proxy": "basic"
}'

2.3 Scrape并具有Extract功能(LLM)

使用 Firecrawl 抓取并提取结构化数据 Firecrawl 利用大型语言模型 (LLM) 高效地从网页中提取结构化数据。具体方法如下:

该方法简化了数据提取,减少了手动处理并提高了效率。

2.3.1 有模式提取

curl -X POST https://host:port/v1/scrape \
-H'Content-Type: application/json'\
-d'{
"url": "https://docs.firecrawl.dev/",
"formats": ["json"],
"jsonOptions": {
"schema": {
"type": "object",
"properties": {
"company_mission": {
"type": "string"
},
"supports_sso": {
"type": "boolean"
},
"is_open_source": {
"type": "boolean"
},
"is_in_yc": {
"type": "boolean"
}
},
"required": [
"company_mission",
"supports_sso",
"is_open_source",
"is_in_yc"
]
}
}
}'

2.3.2 无模式提取

只需将 传递给端点即可提取数据,而无需使用模式prompt。

curl -X POST https://host:port/v1/scrape \
-H'Content-Type: application/json'\
-d'{
"url": "https://docs.firecrawl.dev/",
"formats": ["json"],
"jsonOptions": {
"prompt": "Extract the company mission from the page."
}
}'

2.4 Crawl全站抓取

Firecrawl 可以递归搜索 URL 子域,并收集内容

Firecrawl 会彻底抓取网站,确保全面提取数据,同时绕过任何网络拦截机制。其工作原理如下:

此方法保证从任何起始 URL 进行详尽的抓取和数据收集。

curl -X POST https://host:port/v1/crawl \
-H'Content-Type: application/json'\
-d'{
"url": "https://docs.firecrawl.dev",
"limit": 100,
"scrapeOptions": {
"formats": ["markdown", "html"]
}
}'

2.5 Map抓取全站地图

输入一个网站并获取该网站上的所有网址 - 速度极快

这是将单个 URL 转换为整个网站地图的最简单方法。此功能在以下情况下非常有用:

当你需要提示最终用户选择要抓取的链接时 需要快速了解网站上的链接 需要抓取与特定主题相关的网站页面(使用search参数) 只需抓取网站的特定页面

curl -X POST https://host:port/v1/map \
-H'Content-Type: application/json'\
-d'{
"url": "https://firecrawl.dev"
}'

2.6 Extract 多页面自动抽取

该/extract端点简化了从任意数量的 URL 或整个域收集结构化数据的过程。只需提供一个 URL 列表(可选使用通配符,例如example.com/*),以及描述所需信息的提示符或架构即可。Firecrawl 负责抓取、解析和整理大型或小型数据集的细节。

使用/extract 您可以从一个或多个 URL 中提取结构化数据,包括通配符:

单页 示例:https://firecrawl.dev/some-page 多页面/完整域名 示例:https://firecrawl.dev/* 当您使用 时/*,Firecrawl 会自动抓取并解析其在该域名下发现的所有 URL,然后提取请求的数据。

curl -X POST https://host:port/v1/extract \
-H'Content-Type: application/json'\
-d'{
"urls": [
"https://firecrawl.dev/",
"https://docs.firecrawl.dev/",
"https://www.ycombinator.com/companies"
],
"prompt": "Extract the company mission, whether it supports SSO, whether it is open source, and whether it is in Y Combinator from the page.",
"schema": {
"type": "object",
"properties": {
"company_mission": {
"type": "string"
},
"supports_sso": {
"type": "boolean"
},
"is_open_source": {
"type": "boolean"
},
"is_in_yc": {
"type": "boolean"
}
},
"required": [
"company_mission",
"supports_sso",
"is_open_source",
"is_in_yc"
]
}
}'

三、云版本支持的接入方式

四、云版本和开源版本

Firecrawl 是开源的,根据AGPL-3.0 许可提供。 Firecrawl Cloud 可在firecrawl.dev上获取,云托管提供一系列开源版本所没有的功能。

开源版本和云版本之间的差异,如下图所示:

相同功能

  1. 支持单网页爬取的scrape

  2. 支持正站爬取的crawl

  3. 支持通过LLM进行Extract

  4. 支持爬取站点地图sitemap

5.支持输出LLM友好的格式,markwon,json等

  1. 支持Python、Node、Go、Rust各语言的SDK

云版本额外功能

7. 绕过机器人保护

  1. 代理轮换

  2. 爬取控制台

10.内容交互和点击执行

11.无头浏览器

12.企业版的一些其他特征

五、参考

Quickstart | Firecrawl

Blog

Firecrawl







欢迎光临 链载Ai (https://www.lianzai.com/) Powered by Discuz! X3.5