> ## Documentation Index
> Fetch the complete documentation index at: https://student-213fb9fc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 爬取

> 注意：此 API 的全新 [v2 版本](/zh/api-reference/endpoint/crawl-post) 现已上线，功能和性能均有所提升。


## OpenAPI

````yaml zh/api-reference/v1-openapi.json post /crawl
openapi: 3.0.0
info:
  title: Firecrawl API
  version: v1
  description: 用于与 Firecrawl 服务交互，以进行网页抓取和爬取任务的 API。
  contact:
    name: Firecrawl Support
    url: https://firecrawl.dev/support
    email: support@firecrawl.dev
servers:
  - url: https://api.firecrawl.dev/v1
security:
  - bearerAuth: []
paths:
  /crawl:
    post:
      tags:
        - Crawling
      summary: 根据选项爬取多个 URL
      operationId: crawlUrls
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                url:
                  type: string
                  format: uri
                  description: 开始爬取时使用的起始 URL
                excludePaths:
                  type: array
                  items:
                    type: string
                  description: >-
                    根据 URL pathname 的正则表达式模式，将匹配的 URL 排除在抓取之外。例如，如果你在基础 URL
                    firecrawl.dev 上设置 `"excludePaths":
                    ["blog/.*"]`，那么所有匹配该模式的结果都会被排除，例如：https://www.firecrawl.dev/blog/firecrawl-launch-week-1-recap。
                includePaths:
                  type: array
                  items:
                    type: string
                  description: >-
                    用于在抓取中指定要包含哪些 URL 的 URL
                    路径名正则表达式模式。只有与指定模式匹配的路径才会包含在响应中。例如，如果你为基础 URL firecrawl.dev
                    设置 `"includePaths":
                    ["blog/.*"]`，则只有与该模式匹配的结果会被包含，例如：https://www.firecrawl.dev/blog/firecrawl-launch-week-1-recap。
                regexOnFullURL:
                  type: boolean
                  description: >-
                    如果为 true，includePaths 和 excludePaths 的正则表达式模式将匹配整个
                    URL（包括查询参数），而不仅仅是 URL 的路径名。当你需要基于查询字符串来过滤 URL 时，这会非常有用。
                  default: false
                maxDepth:
                  type: integer
                  description: 从输入 URL 的基础路径开始可爬取的最大绝对深度。简单来说，就是被抓取 URL 的路径名中允许包含的斜杠数量上限。
                  default: 10
                maxDiscoveryDepth:
                  type: integer
                  description: >-
                    基于发现顺序的最大抓取深度。根站点及站点地图中的页面的发现深度为 0。比如，如果你将其设置为 1，并启用
                    ignoreSitemap，你只会抓取输入的 URL，以及该页面上所有被链接到的 URL。
                ignoreSitemap:
                  type: boolean
                  description: 爬取时忽略网站的 sitemap
                  default: false
                ignoreQueryParameters:
                  type: boolean
                  description: 请勿对同一路径使用不同（或无）查询参数进行重复抓取
                  default: false
                limit:
                  type: integer
                  description: 要抓取的最大页面数。默认上限为 10000。
                  default: 10000
                allowBackwardLinks:
                  type: boolean
                  description: >-
                    ⚠️ 已弃用：请改用“crawlEntireDomain”。此选项允许爬虫跟踪指向同级或父级 URL
                    的内部链接，而不仅限于子路径。
                  default: false
                  deprecated: true
                crawlEntireDomain:
                  type: boolean
                  description: |-
                    允许爬虫跟踪到同级或父级的站内链接，而不仅仅是子路径。

                    false：只爬取更深层（子级）URL。
                    → 例如 /features/feature-1 → /features/feature-1/tips ✅
                    → 不会跟踪 /pricing 或 / ❌

                    true：爬取任意站内链接，包括同级和父级。
                    → 例如 /features/feature-1 → /pricing、/ 等 ✅

                    当需要在嵌套路径之外更广泛地覆盖站内链接时，将其设置为 true。
                  default: false
                allowExternalLinks:
                  type: boolean
                  description: 允许爬虫跟随链接访问外部网站。
                  default: false
                allowSubdomains:
                  type: boolean
                  description: 允许爬虫跟随指向主域子域的链接。
                  default: false
                delay:
                  type: number
                  description: 每次抓取之间的延迟时间（秒）。有助于遵守网站的速率限制。
                maxConcurrency:
                  type: integer
                  description: 最大抓取并发数。该参数用于为本次抓取任务设置并发上限；如果未指定，将沿用你团队的并发限制。
                webhook:
                  type: object
                  description: Webhook 规范对象。
                  properties:
                    url:
                      type: string
                      description: >-
                        用于接收 webhook 的 URL。该 webhook
                        会在以下事件中触发：当爬取开始时（crawl.started）、每完成一页爬取时（crawl.page），以及爬取结束时（crawl.completed
                        或 crawl.failed）。响应将与 `/scrape` 端点相同。
                    headers:
                      type: object
                      description: 要发送到 webhook URL 的 HTTP 请求头。
                      additionalProperties:
                        type: string
                    metadata:
                      type: object
                      description: 将包含在本次抓取所有 webhook 负载中的自定义元数据
                      additionalProperties: true
                    events:
                      type: array
                      description: 要发送到 webhook URL 的事件类型。（默认：全部）
                      items:
                        type: string
                        enum:
                          - completed
                          - page
                          - failed
                          - started
                  required:
                    - url
                scrapeOptions:
                  $ref: '#/components/schemas/ScrapeOptions'
                zeroDataRetention:
                  type: boolean
                  default: false
                  description: 如果为 true，则本次爬取将不会保留任何数据。若要启用此功能，请联系 help@firecrawl.dev
              required:
                - url
      responses:
        '200':
          description: 成功的响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CrawlResponse'
        '402':
          description: 需要付费
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Payment required to access this resource.
        '429':
          description: 请求次数过多
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: >-
                      Request rate limit exceeded. Please wait and try again
                      later.
        '500':
          description: 服务器错误
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: An unexpected error occurred on the server.
      security:
        - bearerAuth: []
components:
  schemas:
    ScrapeOptions:
      allOf:
        - $ref: '#/components/schemas/BaseScrapeOptions'
        - type: object
          properties:
            formats:
              type: array
              items:
                type: string
                enum:
                  - markdown
                  - html
                  - rawHtml
                  - links
                  - screenshot
                  - screenshot@fullPage
                  - json
                  - changeTracking
              description: 输出中要包含的formats。
              default:
                - markdown
            changeTrackingOptions:
              type: object
              description: >-
                用于 changeTracking 的选项（Beta）。仅当在 formats 中包含 'changeTracking'
                时才适用。使用 changeTracking 时，还必须同时指定 'markdown' 格式。
              properties:
                modes:
                  type: array
                  items:
                    type: string
                    enum:
                      - git-diff
                      - json
                  description: 用于更改跟踪的模式。`git-diff` 提供详细的差异对比，而 `json` 用于比较提取的 JSON 数据。
                schema:
                  type: object
                  description: >-
                    在使用 `json` 模式时用于 JSON 提取的 schema。用于定义要提取和对比的数据结构。必须符合 [JSON
                    Schema](https://json-schema.org/) 规范。
                prompt:
                  type: string
                  description: 在使用 JSON 模式进行变更跟踪时要使用的提示。如果未提供，则会使用默认提示。
                tag:
                  type: string
                  nullable: true
                  default: null
                  description: >-
                    用于变更跟踪的标签。标签可以将变更跟踪历史划分为不同的「分支」，使用特定标签的变更跟踪只会与同一标签下的抓取结果进行比较。如果未提供，则会使用默认标签（null）。
    CrawlResponse:
      type: object
      properties:
        success:
          type: boolean
        id:
          type: string
        url:
          type: string
          format: uri
    BaseScrapeOptions:
      type: object
      properties:
        onlyMainContent:
          type: boolean
          description: 仅返回页面的主体内容，不包括页眉、导航、页脚等。
          default: true
        includeTags:
          type: array
          items:
            type: string
          description: 需要包含在输出中的标签。
        excludeTags:
          type: array
          items:
            type: string
          description: 在输出结果中要排除的标签。
        maxAge:
          type: integer
          description: >-
            如果页面的缓存版本的生成时间距现在小于此值（毫秒），则返回该缓存版本；如果缓存版本早于此值，则会重新抓取页面。如果你不需要极其实时的数据，启用此选项可以将抓取速度最多提升
            5 倍。默认值为 0，表示禁用缓存。
          default: 0
        headers:
          type: object
          description: 随请求发送的请求头。可用于携带 cookies、user-agent 等信息。
        waitFor:
          type: integer
          description: 设置在获取内容前的延迟时间（毫秒），以便页面有足够时间加载完成。
          default: 0
        mobile:
          type: boolean
          description: 若要模拟移动端抓取，请将其设置为 true。适用于测试响应式页面并获取移动端截图。
          default: false
        skipTlsVerification:
          type: boolean
          description: 在发送请求时跳过 TLS 证书校验
          default: false
        timeout:
          type: integer
          description: 请求超时时间（毫秒）
          default: 30000
        parsePDF:
          type: boolean
          description: >-
            控制在爬取过程中如何处理 PDF 文件。为 true 时，会提取 PDF 内容并转换为 Markdown 格式，按页数计费（每页 1
            个积分）。为 false 时，会返回以 base64 编码的 PDF 文件，统一按 1 个积分计费。
          default: true
        jsonOptions:
          type: object
          description: JSON 配置对象
          properties:
            schema:
              type: object
              description: 用于提取的数据模式（可选）。必须符合 [JSON Schema](https://json-schema.org/) 规范。
            systemPrompt:
              type: string
              description: 用于抽取的系统提示（可选）
            prompt:
              type: string
              description: 在无 schema 情况下用于抽取的数据提示词（可选）
        actions:
          type: array
          description: 在抓取页面内容前需要执行的 actions
          items:
            oneOf:
              - type: object
                title: Wait
                properties:
                  type:
                    type: string
                    enum:
                      - wait
                    description: 等待指定的毫秒数
                  milliseconds:
                    type: integer
                    minimum: 1
                    description: 等待的时间（毫秒）
                  selector:
                    type: string
                    description: 用于定位该元素的查询选择器
                    example: '#my-element'
                required:
                  - type
              - type: object
                title: Screenshot
                properties:
                  type:
                    type: string
                    enum:
                      - screenshot
                    description: 进行截图。链接将位于响应的 `actions.screenshots` 数组中。
                  fullPage:
                    type: boolean
                    description: 是否截取整页截图，或仅截取当前视口。
                    default: false
                  quality:
                    type: integer
                    description: 截图质量，取值范围为 1 至 100，100 为最高质量。
                required:
                  - type
              - type: object
                title: Click
                properties:
                  type:
                    type: string
                    enum:
                      - click
                    description: 单击元素
                  selector:
                    type: string
                    description: 用于查找元素的查询选择器
                    example: '#load-more-button'
                  all:
                    type: boolean
                    description: 点击所有匹配该选择器的元素，而不仅仅是第一个元素。如果没有元素匹配该选择器，也不会抛出错误。
                    default: false
                required:
                  - type
                  - selector
              - type: object
                title: Write text
                properties:
                  type:
                    type: string
                    enum:
                      - write
                    description: >-
                      在输入框、文本区域或 contenteditable
                      元素中写入文本。注意：在写入之前，必须先通过一次“click”操作使该元素获得焦点。文本将以逐字符输入的方式进行，以模拟键盘敲击。
                  text:
                    type: string
                    description: 输入文本
                    example: Hello, world!
                required:
                  - type
                  - text
              - type: object
                title: Press a key
                description: >-
                  请在页面上按下任意键。按键代码请参考：https://asawicki.info/nosense/doc/devices/keyboard/key_codes.html。
                properties:
                  type:
                    type: string
                    enum:
                      - press
                    description: 在页面上按下任意键
                  key:
                    type: string
                    description: 按键
                    example: Enter
                required:
                  - type
                  - key
              - type: object
                title: Scroll
                properties:
                  type:
                    type: string
                    enum:
                      - scroll
                    description: 滚动页面或特定元素
                  direction:
                    type: string
                    enum:
                      - up
                      - down
                    description: 滚动方向
                    default: down
                  selector:
                    type: string
                    description: 需要滚动的元素的查询选择器
                    example: '#my-element'
                required:
                  - type
              - type: object
                title: Scrape
                properties:
                  type:
                    type: string
                    enum:
                      - scrape
                    description: 抓取当前页面内容，同时返回其 URL 和 HTML。
                required:
                  - type
              - type: object
                title: Execute JavaScript
                properties:
                  type:
                    type: string
                    enum:
                      - executeJavascript
                    description: 在页面上执行 JavaScript 代码
                  script:
                    type: string
                    description: 待执行的 JavaScript 代码
                    example: document.querySelector('.button').click();
                required:
                  - type
                  - script
              - type: object
                title: Generate PDF
                properties:
                  type:
                    type: string
                    enum:
                      - pdf
                    description: 生成当前页面的 PDF。该 PDF 将在响应中的 `actions.pdfs` 数组里返回。
                  format:
                    type: string
                    enum:
                      - A0
                      - A1
                      - A2
                      - A3
                      - A4
                      - A5
                      - A6
                      - Letter
                      - Legal
                      - Tabloid
                      - Ledger
                    description: 生成的 PDF 的页面大小
                    default: Letter
                  landscape:
                    type: boolean
                    description: 是否以横向页面方向生成 PDF 文件
                    default: false
                  scale:
                    type: number
                    description: 生成的 PDF 的缩放比例
                    default: 1
                required:
                  - type
        location:
          type: object
          description: 请求的地理位置设置。指定后，如果可用，将使用合适的代理服务器，并模拟相应的语言和时区设置。如果未指定，默认值为“US”。
          properties:
            country:
              type: string
              description: ISO 3166-1 alpha-2 两位字母国家代码（例如：“US”、“AU”、“DE”、“JP”）
              pattern: ^[A-Z]{2}$
              default: US
            languages:
              type: array
              description: >-
                按照优先级为本次请求指定首选语言和区域设置。默认使用所指定地区的语言。详见：https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
              items:
                type: string
                example: en-US
        removeBase64Images:
          type: boolean
          description: 从输出中移除所有 Base64 图片，以避免内容过于冗长。图片的替代文本（alt 文本）会保留在输出中，但其 URL 会被占位符替换。
          default: true
        blockAds:
          type: boolean
          description: 启用广告拦截和 Cookie 弹窗屏蔽。
          default: true
        proxy:
          type: string
          enum:
            - basic
            - enhanced
            - auto
          description: |-
            指定要使用的代理类型。

             - **basic**：适用于抓取没有或仅有基础防爬机制网站的代理。速度快，通常足够好用。
             - **enhanced**：适用于抓取具有高级防爬机制网站的增强型代理。速度较慢，但在某些网站上更可靠。每次请求最多消耗 5 个积分。
             - **auto**：当使用 basic 代理抓取失败时，Firecrawl 会自动使用 enhanced 代理重试。如果使用 enhanced 重试成功，该次抓取将收取 5 个积分；如果首次使用 basic 即抓取成功，则只收取常规费用。

            如果未指定代理类型，Firecrawl 将默认使用 basic。
        storeInCache:
          type: boolean
          description: >-
            如果为 true，该页面将被存储到 Firecrawl 的索引和缓存中。若你的抓取活动可能涉及数据保护方面的问题，将其设置为 false
            会更合适。使用某些与敏感抓取相关的参数（如 actions、headers）时，该参数会被强制设为 false。
          default: true
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````