介绍 /map

从单个 URL 快速生成整站链接地图的最简方式。这在以下场景特别有用:
  • 需要让终端用户选择要抓取的链接时
  • 需要快速了解网站包含哪些链接
  • 需要抓取与特定主题相关的页面(使用 search 参数)
  • 只需抓取网站中的特定页面

映射

/map 端点

用于映射一个 URL 并获取该网站的 URL。会返回站点上大部分的链接。

安装

# 使用 pip 安装 firecrawl-py

from firecrawl import Firecrawl

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")

使用方法

from firecrawl import Firecrawl

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")
res = firecrawl.map(url="https://firecrawl.dev", limit=50, sitemap="include")
print(res)

响应

SDK 会直接返回数据对象。cURL 会按下方所示原样返回负载。
{
  "success": true,
  "links": [
    {
      "url": "https://docs.firecrawl.dev/features/scrape",
      "title": "Scrape | Firecrawl",
      "description": "Turn any url into clean data"
    },
    {
      "url": "https://www.firecrawl.dev/blog/5_easy_ways_to_access_glm_4_5",
      "title": "5 Easy Ways to Access GLM-4.5",
      "description": "Discover how to access GLM-4.5 models locally, through chat applications, via the official API, and using the LLM marketplaces API for seamless integration i..."
    },
    {
      "url": "https://www.firecrawl.dev/playground",
      "title": "Playground - Firecrawl",
      "description": "Preview the API response and get the code snippets for the API"
    },
    {
      "url": "https://www.firecrawl.dev/?testId=2a7e0542-077b-4eff-bec7-0130395570d6",
      "title": "Firecrawl - The Web Data API for AI",
      "description": "The web crawling, scraping, and search API for AI. Built for scale. Firecrawl delivers the entire internet to AI agents and builders. Clean, structured, and ..."
    },
    {
      "url": "https://www.firecrawl.dev/?testId=af391f07-ca0e-40d3-8ff2-b1ecf2e3fcde",
      "title": "Firecrawl - The Web Data API for AI",
      "description": "The web crawling, scraping, and search API for AI. Built for scale. Firecrawl delivers the entire internet to AI agents and builders. Clean, structured, and ..."
    },
    ...
  ]
}
标题和描述不一定都会提供,具体取决于网站。
使用 search 参数的 Map 可在站内搜索特定的 URL。
cURL
curl -X POST https://api.firecrawl.dev/v2/map \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -d '{
    "url": "https://firecrawl.dev",
    "search": "docs"
  }'
响应将按相关性从高到低返回一个有序列表。
{
  "status": "success",
  "links": [
    {
      "url": "https://docs.firecrawl.dev",
      "title": "Firecrawl 文档",
      "description": "Firecrawl 文档"
    },
    {
      "url": "https://docs.firecrawl.dev/sdks/python",
      "title": "Firecrawl Python SDK",
      "description": "Firecrawl Python SDK 文档"
    },
    ...
  ]
}

位置与语言

指定国家和首选语言,根据你的目标位置与语言偏好获取更相关的内容,方式与 /scrape 端点相似。

工作原理

当你指定位置设置时,Firecrawl 会在可用时使用合适的代理,并模拟相应的语言和时区设置。默认情况下,若未指定,位置将设为“US”。

用法

要配置位置和语言,请在请求体中包含 location 对象,并设置以下属性:
  • country:ISO 3166-1 alpha-2 国家代码(如 ‘US’、‘AU’、‘DE’、‘JP’)。默认值为 ‘US’。
  • languages:按优先级排序的首选语言与区域设置数组。默认使用所设位置的语言。
from firecrawl import Firecrawl

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")

res = firecrawl.map('https://example.com',
    location={
        'country': 'US',
        'languages': ['en']
    }
)

print(res)
有关支持的地区与位置的更多信息,请参见 Proxies 文档

注意事项

该端点以速度为先,因此可能无法捕获所有站点链接。我们正在改进中,欢迎提出反馈和建议。