OA0 = Omni AI 0
OA0 是一个探索 AI 的论坛
现在注册
已注册用户请  登录
OA0  ›  技能包  ›  firecrawl-skills:用于网页抓取、爬虫与搜索的 Firecrawl 命令行工具

firecrawl-skills:用于网页抓取、爬虫与搜索的 Firecrawl 命令行工具

 
  gateway ·  2026-02-16 09:36:37 · 3 次点击  · 0 条评论  

名称: firecrawl-cli
描述: |
Firecrawl CLI 是一款用于网页抓取、爬取和搜索的工具。可抓取单个页面或整个网站、映射站点 URL,并进行支持完整内容提取的网络搜索。返回经过优化的纯净 Markdown,适用于 LLM 上下文。可用于研究、文档提取、竞争情报和内容监控。


Firecrawl CLI

使用 firecrawl CLI 来获取和搜索网络内容。Firecrawl 返回经过优化的纯净 Markdown,适用于 LLM 上下文窗口,能处理 JavaScript 渲染、绕过常见拦截,并提供结构化数据。

安装

检查状态、认证和速率限制:

firecrawl --status

准备就绪时的输出示例:

  🔥 firecrawl cli v1.0.2

  ● 已通过 FIRECRAWL_API_KEY 认证
  并发数:0/100 个任务(并行抓取限制)
  点数:剩余 500,000
  • 并发数:最大并行任务数。运行并行操作时应接近但不超过此限制。
  • 点数:剩余的 API 点数。每次抓取/爬取都会消耗点数。

如果尚未安装:npm install -g firecrawl-cli

如果用户未登录,请务必参考 rules/install.md 中的安装规则以获取更多信息。

认证

如果未认证,请运行:

firecrawl login --browser

--browser 标志会自动打开浏览器进行认证,无需提示。

组织管理

在工作目录中创建 .firecrawl/ 文件夹(如果尚不存在)以存储结果。如果尚未添加,请将 .firecrawl/ 添加到 .gitignore 文件中。始终使用 -o 选项直接将结果写入文件(避免上下文信息过多):

# 搜索网络(最常用操作)
firecrawl search "你的查询" -o .firecrawl/search-{query}.json

# 启用抓取功能的搜索
firecrawl search "你的查询" --scrape -o .firecrawl/search-{query}-scraped.json

# 抓取单个页面
firecrawl scrape https://example.com -o .firecrawl/{site}-{path}.md

示例:

.firecrawl/search-react_server_components.json
.firecrawl/search-ai_news-scraped.json
.firecrawl/docs.github.com-actions-overview.md
.firecrawl/firecrawl.dev.md

命令

搜索 - 网络搜索(可选抓取)

# 基础搜索(人类可读输出)
firecrawl search "你的查询" -o .firecrawl/search-query.txt

# JSON 输出(推荐用于解析)
firecrawl search "你的查询" -o .firecrawl/search-query.json --json

# 限制结果数量
firecrawl search "AI news" --limit 10 -o .firecrawl/search-ai-news.json --json

# 搜索特定来源
firecrawl search "tech startups" --sources news -o .firecrawl/search-news.json --json
firecrawl search "landscapes" --sources images -o .firecrawl/search-images.json --json
firecrawl search "machine learning" --sources web,news,images -o .firecrawl/search-ml.json --json

# 按类别筛选(GitHub 仓库、研究论文、PDF)
firecrawl search "web scraping python" --categories github -o .firecrawl/search-github.json --json
firecrawl search "transformer architecture" --categories research -o .firecrawl/search-research.json --json

# 基于时间的搜索
firecrawl search "AI announcements" --tbs qdr:d -o .firecrawl/search-today.json --json  # 过去一天
firecrawl search "tech news" --tbs qdr:w -o .firecrawl/search-week.json --json          # 过去一周

# 基于位置的搜索
firecrawl search "restaurants" --location "San Francisco,California,United States" -o .firecrawl/search-sf.json --json
firecrawl search "local news" --country DE -o .firecrawl/search-germany.json --json

# 搜索并抓取结果中的内容
firecrawl search "firecrawl tutorials" --scrape -o .firecrawl/search-scraped.json --json
firecrawl search "API docs" --scrape --scrape-formats markdown,links -o .firecrawl/search-docs.json --json

搜索选项:

选项 描述
--limit <n> 最大结果数(默认:5,最大:100)
--sources <sources> 逗号分隔的来源:web, images, news(默认:web)
--categories <categories> 逗号分隔的类别:github, research, pdf
--tbs <value> 时间过滤器:qdr:h(小时),qdr:d(天),qdr:w(周),qdr:m(月),qdr:y(年)
--location <location> 地理定位(例如:"Germany")
--country <code> ISO 国家代码(默认:US)
--scrape 启用对搜索结果的抓取
--scrape-formats <formats> 启用 --scrape 时的抓取格式(默认:markdown)
-o, --output <path> 保存到文件

抓取 - 单页内容提取

# 基础抓取(Markdown 输出)
firecrawl scrape https://example.com -o .firecrawl/example.md

# 获取原始 HTML
firecrawl scrape https://example.com --html -o .firecrawl/example.html

# 多种格式(JSON 输出)
firecrawl scrape https://example.com --format markdown,links -o .firecrawl/example.json

# 仅主要内容(移除导航、页脚、广告)
firecrawl scrape https://example.com --only-main-content -o .firecrawl/example.md

# 等待 JS 渲染
firecrawl scrape https://spa-app.com --wait-for 3000 -o .firecrawl/spa.md

# 仅提取链接
firecrawl scrape https://example.com --format links -o .firecrawl/links.json

# 包含/排除特定的 HTML 标签
firecrawl scrape https://example.com --include-tags article,main -o .firecrawl/article.md
firecrawl scrape https://example.com --exclude-tags nav,aside,.ad -o .firecrawl/clean.md

抓取选项:

选项 描述
-f, --format <formats> 输出格式:markdown, html, rawHtml, links, screenshot, json
-H, --html --format html 的快捷方式
--only-main-content 仅提取主要内容
--wait-for <ms> 抓取前等待(针对 JS 内容)
--include-tags <tags> 仅包含特定的 HTML 标签
--exclude-tags <tags> 排除特定的 HTML 标签
-o, --output <path> 保存到文件

爬取 - 爬取整个网站

# 开始爬取(返回任务 ID)
firecrawl crawl https://example.com

# 等待爬取完成
firecrawl crawl https://example.com --wait

# 带进度指示器
firecrawl crawl https://example.com --wait --progress

# 检查爬取状态
firecrawl crawl <job-id>

# 限制页面数量
firecrawl crawl https://example.com --limit 100 --max-depth 3

# 仅爬取博客部分
firecrawl crawl https://example.com --include-paths /blog,/posts

# 排除管理页面
firecrawl crawl https://example.com --exclude-paths /admin,/login

# 带速率限制的爬取
firecrawl crawl https://example.com --delay 1000 --max-concurrency 2

# 保存结果
firecrawl crawl https://example.com --wait -o crawl-results.json --pretty

爬取选项:

选项 描述
--wait 等待爬取完成
--progress 等待时显示进度
--limit <n> 最大爬取页面数
--max-depth <n> 最大爬取深度
--include-paths <paths> 仅爬取匹配的路径
--exclude-paths <paths> 跳过匹配的路径
--delay <ms> 请求之间的延迟
--max-concurrency <n> 最大并发请求数

映射 - 发现站点上的所有 URL

# 列出所有 URL(每行一个)
firecrawl map https://example.com -o .firecrawl/urls.txt

# 输出为 JSON
firecrawl map https://example.com --json -o .firecrawl/urls.json

# 搜索特定 URL
firecrawl map https://example.com --search "blog" -o .firecrawl/blog-urls.txt

# 限制结果数量
firecrawl map https://example.com --limit 500 -o .firecrawl/urls.txt

# 包含子域名
firecrawl map https://example.com --include-subdomains -o .firecrawl/all-urls.txt

映射选项:

选项 描述
--limit <n> 最大发现 URL 数
--search <query> 按搜索查询筛选 URL
--sitemap <mode> 包含、跳过或仅使用站点地图
--include-subdomains 包含子域名
--json 输出为 JSON
-o, --output <path> 保存到文件

点数使用情况

# 显示点数使用情况
firecrawl credit-usage

# 输出为 JSON
firecrawl credit-usage --json --pretty

读取抓取的文件

除非明确要求,否则切勿一次性读取整个 firecrawl 输出文件——它们可能超过 1000 行。应使用 grep、head 或增量读取:

# 检查文件大小并预览结构
wc -l .firecrawl/file.md && head -50 .firecrawl/file.md

# 使用 grep 查找特定内容
grep -n "keyword" .firecrawl/file.md
grep -A 10 "## Section" .firecrawl/file.md

并行处理

使用 &wait 并行运行多个抓取任务:

# 并行抓取(快速)
firecrawl scrape https://site1.com -o .firecrawl/1.md &
firecrawl scrape https://site2.com -o .firecrawl/2.md &
firecrawl scrape https://site3.com -o .firecrawl/3.md &
wait

对于大量 URL,可使用带 -P 参数的 xargs 进行并行执行:

cat urls.txt | xargs -P 10 -I {} sh -c 'firecrawl scrape "{}" -o ".firecrawl/$(echo {} | md5).md"'

与其他工具结合使用

# 从搜索结果中提取 URL
jq -r '.data.web[].url' .firecrawl/search-query.json

# 从搜索结果中获取标题
jq -r '.data.web[] | "\(.title): \(.url)"' .firecrawl/search-query.json

# 统计映射结果中的 URL 数量
firecrawl map https://example.com | wc -l
3 次点击  ∙  0 人收藏  
登录后收藏  
目前尚无回复
0 条回复
About   ·   Help   ·    
OA0 - Omni AI 0 一个探索 AI 的社区
沪ICP备2024103595号-2
Developed with Cursor