> ## 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/scrape) 现已上线，提供更强大的功能和更高的性能。


## OpenAPI

````yaml zh/api-reference/v1-openapi.json post /scrape
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:
  /scrape:
    post:
      tags:
        - Scraping
      summary: 抓取单个 URL，并可选择使用 LLM 提取信息
      operationId: scrapeAndExtractFromUrl
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - type: object
                  properties:
                    url:
                      type: string
                      format: uri
                      description: 要爬取的 URL
                  required:
                    - url
                - $ref: '#/components/schemas/ScrapeOptions'
                - type: object
                  properties:
                    zeroDataRetention:
                      type: boolean
                      default: false
                      description: 如果为 true，将对本次抓取启用零数据保留策略。要开启此功能，请联系 help@firecrawl.dev
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScrapeResponse'
        '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）。
    ScrapeResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          type: object
          properties:
            markdown:
              type: string
            html:
              type: string
              nullable: true
              description: >-
                当 `formats` 中包含 `html` 时，返回页面的已清理 HTML：会移除
                `<script>`、`<style>`、`<noscript>`、`<meta>` 和 `<head>` 标签；将相对 URL
                转换为绝对 URL；并将响应式图片的 `srcset` 解析为尺寸最大的版本。同时会应用
                `onlyMainContent`、`includeTags` 和 `excludeTags` 过滤器。
            rawHtml:
              type: string
              nullable: true
              description: 当 `formats` 中包含 `rawHtml` 时，将返回从页面获取的原始、未处理的 HTML，不会执行任何清洗或过滤操作。
            screenshot:
              type: string
              nullable: true
              description: 如果在 `formats` 中包含 `screenshot`，将返回该页面的截图。截图将在 24 小时后失效，之后将无法再下载。
            links:
              type: array
              items:
                type: string
              description: 当 `formats` 中包含 `links` 时，页面上的链接列表
            actions:
              type: object
              nullable: true
              description: '`actions` 参数中各项 actions 的执行结果。仅当请求中提供了 `actions` 参数时才会包含此字段。'
              properties:
                screenshots:
                  type: array
                  description: 截图 URL，与提供的截图 actions 顺序一致。截图将在 24 小时后过期，之后将无法再下载。
                  items:
                    type: string
                    format: url
                scrapes:
                  type: array
                  description: 按照提供的 scrape actions 的顺序抓取内容。
                  items:
                    type: object
                    properties:
                      url:
                        type: string
                      html:
                        type: string
                javascriptReturns:
                  type: array
                  description: JavaScript 的返回值，其顺序与提供的 executeJavascript actions 相同。
                  items:
                    type: object
                    properties:
                      type:
                        type: string
                      value: {}
                pdfs:
                  type: array
                  description: 生成的 PDF，其顺序与提供的 pdf actions 保持一致。
                  items:
                    type: string
            metadata:
              type: object
              properties:
                title:
                  type: string
                description:
                  type: string
                language:
                  type: string
                  nullable: true
                sourceURL:
                  type: string
                  format: uri
                keywords:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                  description: 从页面中提取的关键词，可以为字符串或字符串数组
                ogLocaleAlternate:
                  type: array
                  items:
                    type: string
                  description: 此页面的其他语言版本
                '<any other metadata> ':
                  type: string
                statusCode:
                  type: integer
                  description: 页面状态码
                error:
                  type: string
                  nullable: true
                  description: 页面错误信息
            llm_extraction:
              type: object
              description: 在使用 LLM 提取时显示。根据定义的 schema 从页面中提取的数据。
              nullable: true
            warning:
              type: string
              nullable: true
              description: 在使用 LLM Extraction 时显示。警告信息会提示你提取过程中的任何问题。
            changeTracking:
              type: object
              nullable: true
              description: >-
                当 `formats` 中包含 `changeTracking` 时，会返回变更追踪信息。仅在请求
                `changeTracking` format 时才会提供。
              properties:
                previousScrapeAt:
                  type: string
                  format: date-time
                  nullable: true
                  description: 用于与当前页面进行比较的上一次抓取时间戳。如果不存在之前的抓取记录，则为 null。
                changeStatus:
                  type: string
                  enum:
                    - new
                    - same
                    - changed
                    - removed
                  description: >-
                    两个页面版本比较的结果。`new` 表示该页面之前不存在，`same` 表示内容没有变化，`changed`
                    表示内容发生了变化，`removed` 表示该页面已被移除。
                visibility:
                  type: string
                  enum:
                    - visible
                    - hidden
                  description: >-
                    当前页面/URL 的可见性。"visible" 表示该 URL 是通过自然路径（链接或
                    sitemap）发现的，"hidden" 表示该 URL 是通过之前抓取结果的记忆发现的。
                diff:
                  type: string
                  nullable: true
                  description: 在使用“git-diff”模式时生成的 Git 风格差异（diff）。仅在模式设置为“git-diff”时才会出现。
                json:
                  type: object
                  nullable: true
                  description: >-
                    在使用 `json` 模式时的 JSON 比较结果。仅在模式设置为 `json` 时可用。它会根据 `schema`
                    中定义的类型，返回 `previous` 和 `current`
                    抓取结果中所有键及其对应值的列表。示例参见[这里](/features/change-tracking)
    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

````