scrapfly-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Scrapfly: Web Scraping, Rendering, and Browser Automation

Scrapfly:网页抓取、渲染与浏览器自动化

Scrapfly gives AI agents and applications access to the web through five products: scraping, screenshots, AI extraction, recursive crawling, and a remote browser that you can drive directly over CDP, through a persistent session daemon, or hand to an LLM agent.
This CLI,
scrapfly
, is the single surface over all five products plus a Playwright-MCP-style agent mode. It speaks JSON by default so LLM callers can pipe it directly.
Scrapfly 通过五项产品让 AI Agent 和应用程序能够访问 Web:网页抓取、屏幕截图、AI 数据提取、递归爬取,以及可直接通过 CDP 驱动、通过持久化会话守护进程使用,或交给 LLM Agent 使用的远程浏览器。
此 CLI
scrapfly
是上述五项产品以及一种 Playwright-MCP 风格 Agent 模式的统一入口。默认使用 JSON 通信,因此 LLM 调用方可以直接通过管道传入。

Installation

安装

Pre-built binaries (macOS universal, Linux amd64/arm64, Windows amd64) on the Releases page. Or from source:
bash
go install github.com/scrapfly/scrapfly-cli/cmd/scrapfly@latest
可在 Releases 页面获取预构建的二进制文件(macOS universal、Linux amd64/arm64、Windows amd64)。也可以从源代码安装:
bash
go install github.com/scrapfly/scrapfly-cli/cmd/scrapfly@latest

Six Usage Paths

六条使用路径

Path A (Fetch content):
scrapfly scrape <url>
- the default. Covers every
ScrapeConfig
field from the SDK:
  • Render & navigate:
    --render-js
    ,
    --wait-for-selector
    ,
    --rendering-wait
    ,
    --rendering-stage
    ,
    --auto-scroll
    ,
    --js-file FILE
    ,
    --js-scenario-file FILE
  • Anti-bot:
    --unblocker
    (
    --asp
    is the deprecated alias and still works),
    --cost-budget N
    ,
    --proxy-pool
    ,
    --country
    ,
    --geolocation
  • Format & extraction:
    --format markdown|clean_html|text|raw
    +
    --format-option
    ;
    --extraction-prompt
    ,
    --extraction-model
    ,
    --extraction-template
    ,
    --extraction-template-file FILE
    (ephemeral inline template)
  • Request shape:
    --method
    ,
    --header k=v
    ,
    --cookie n=v
    ,
    --body
    ,
    --body-file
    ,
    --data-file FILE
    (structured body as JSON map),
    --lang
    ,
    --os
    ,
    --browser-brand
  • Sessions & caching:
    --session
    ,
    --session-sticky-proxy
    ,
    --cache
    ,
    --cache-ttl N
    ,
    --cache-clear
    ,
    --retry=true|false
  • Screenshots on scrape:
    --screenshot
    (fullpage shortcut),
    --screenshot-named name=selector
    (repeatable),
    --screenshot-flag FLAG
  • Observability:
    --debug
    ,
    --ssl
    ,
    --dns
    ,
    --correlation-id
    ,
    --tag
    ,
    --webhook NAME
    ,
    --timing
  • Batch: multiple positional URLs or
    --from-file PATH|-
    +
    --concurrency
    (ndjson on stdout)
  • Pipe-friendly:
    --proxified
    streams the raw upstream body with no JSON envelope
Path B (Binary / structured outputs): dedicated commands for focused products.
  • scrapfly screenshot <url>
    - JPG (default), PNG, WebP or GIF of the page or a selector. Full
    ScreenshotConfig
    surface:
    --format
    ,
    --capture
    ,
    --resolution
    ,
    --country
    ,
    --option
    ,
    --wait-for-selector
    ,
    --rendering-wait
    ,
    --auto-scroll
    ,
    --js-file
    ,
    --cache
    ,
    --cache-ttl
    ,
    --cache-clear
    ,
    --webhook
    ,
    --vision-deficiency
    .
  • scrapfly extract --file page.html --prompt "..."
    - run AI/template extraction on a document you already fetched. Full
    ExtractionConfig
    : body via
    --file
    or stdin;
    --content-type
    ,
    --url
    ,
    --charset
    ,
    --prompt | --model | --template | --template-file
    (one of four extraction modes),
    --compression
    ,
    --webhook
    ,
    --request-timeout
    .
  • scrapfly crawl run <url> --max-pages N
    - recursive crawls with status polling, content streaming, WARC/HAR artifacts. Post-download:
    crawl parse har-list|har-get|warc-list|warc-get
    reads the artifact directly (no separate tooling). See the Crawler section below.
Path C (Interactive browser - one-shot): mint a CDP WebSocket URL to hand to Playwright, Puppeteer, or
browser-use
:
bash
undefined
路径 A(获取内容):
scrapfly scrape <url>
——默认方式。覆盖 SDK 中的每个
ScrapeConfig
字段:
  • 渲染与导航:
    --render-js
    、
    --wait-for-selector
    、
    --rendering-wait
    、
    --rendering-stage
    、
    --auto-scroll
    、
    --js-file FILE
    、
    --js-scenario-file FILE
  • 反爬:
    --unblocker
    (
    --asp
    是已弃用的别名,但仍然可用)、
    --cost-budget N
    、
    --proxy-pool
    、
    --country
    、
    --geolocation
  • 格式与提取:
    --format markdown|clean_html|text|raw
    +
    --format-option
    ;
    --extraction-prompt
    、
    --extraction-model
    、
    --extraction-template
    、
    --extraction-template-file FILE
    (临时内联模板)
  • 请求配置:
    --method
    、
    --header k=v
    、
    --cookie n=v
    、
    --body
    、
    --body-file
    、
    --data-file FILE
    (以 JSON map 表示的结构化正文)、
    --lang
    、
    --os
    、
    --browser-brand
  • 会话与缓存:
    --session
    、
    --session-sticky-proxy
    、
    --cache
    、
    --cache-ttl N
    、
    --cache-clear
    、
    --retry=true|false
  • 抓取时截图:
    --screenshot
    (全页面快捷方式)、
    --screenshot-named name=selector
    (可重复使用)、
    --screenshot-flag FLAG
  • 可观测性:
    --debug
    、
    --ssl
    、
    --dns
    、
    --correlation-id
    、
    --tag
    、
    --webhook NAME
    、
    --timing
  • 批处理:多个位置 URL 参数,或使用
    --from-file PATH|-
    +
    --concurrency
    (在 stdout 上输出 ndjson)
  • 便于管道处理:
    --proxified
    会直接流式输出原始上游正文,不带 JSON 信封
路径 B(二进制/结构化输出): 多个专用命令用于聚焦各项产品。
  • scrapfly screenshot <url>
    ——以 JPG(默认)、PNG、WebP 或 GIF 格式生成页面或选择器的图像。提供完整的
    ScreenshotConfig
    选项:
    --format
    、
    --capture
    、
    --resolution
    、
    --country
    、
    --option
    、
    --wait-for-selector
    、
    --rendering-wait
    、
    --auto-scroll
    、
    --js-file
    、
    --cache
    、
    --cache-ttl
    、
    --cache-clear
    、
    --webhook
    、
    --vision-deficiency
    。
  • scrapfly extract --file page.html --prompt "..."
    ——对已经获取的文档执行 AI/模板提取。提供完整的
    ExtractionConfig
    :通过
    --file
    或 stdin 提供正文;支持
    --content-type
    、
    --url
    、
    --charset
    、
    --prompt | --model | --template | --template-file
    (四种提取模式之一)、
    --compression
    、
    --webhook
    、
    --request-timeout
    。
  • scrapfly crawl run <url> --max-pages N
    ——执行递归爬取,支持状态轮询、内容流式传输以及 WARC/HAR 工件。下载后可直接使用
    crawl parse har-list|har-get|warc-list|warc-get
    读取工件,无需其他工具。详见下方 Crawler 部分。
路径 C(交互式浏览器——一次性): 生成 CDP WebSocket URL,以交给 Playwright、Puppeteer 或
browser-use
:
bash
undefined

plain session

plain session

scrapfly browser --pretty
scrapfly browser --pretty

pre-navigate through /unblock so the target's anti-bot is bypassed

pre-navigate through /unblock so the target's anti-bot is bypassed

scrapfly browser https://target.example.com --unblock --country us --pretty

`browser --unblock` and `scrape --unblocker` are two different products with
confusingly similar names: `--unblock` opens a Cloud Browser session through
`POST /unblock`, while `--unblocker` is the anti-bot bypass on a stateless
`scrape` or `crawl`.

**Path D (Interactive browser - persistent daemon):** keep one CDP session
open across many CLI calls. Cookies, tabs, and AXTree refs all persist for
the daemon's lifetime. `--session` is needed only on `start`; subsequent
calls auto-resolve via `~/.scrapfly/sessions/.current`.

```bash
scrapfly browser --session demo --session-timeout 1800 start &
scrapfly browser navigate https://web-scraping.dev/login
scrapfly browser wait 'input[name=username]' --visible
scrapfly browser fill 'input[name=username]' user123
scrapfly browser fill 'input[name=password]' password
scrapfly browser click 'button[type=submit]'
scrapfly browser content --raw > page.html         # fully rendered HTML
scrapfly browser eval 'document.body.innerText'
scrapfly browser close                             # daemon + remote release
When running against Scrapfly's custom browser,
fill
/
click
/
wait
/
slide
automatically use the Antibot CDP domain for human-like timing;
content
uses Page.getRenderedContent which inlines iframe content. Against a non-Scrapfly browser, the CLI falls back to raw
Input.*
events.
Path E (LLM agent):
scrapfly agent "<task>" --url <target>
runs an autonomous loop. The model picks tool calls (open, snapshot, click, fill, scroll, screenshot, eval, unblock, done), the CLI executes them against the Browser, and the result feeds back until the model calls
done
. Providers are pluggable: Anthropic (default), OpenAI, Gemini, or local (Ollama / OpenAI-compatible). AXTree-based observations keep the token budget small.
Path F (REST API only): skip the CLI, call
https://api.scrapfly.io/{scrape,screenshot,extraction,crawl}
directly with
?key=<API_KEY>
. Official SDKs: Python, TypeScript, Go, Rust. See docs.scrapfly.io.
Path G (Alerting on account metrics):
scrapfly alert ...
defines threshold rules on Scrapfly's monitoring metrics (success rate, block rate, error count, cost, latency, ...) and routes notifications via email, webhook, or in-app. Enterprise plan.
bash
undefined
scrapfly browser https://target.example.com --unblock --country us --pretty

`browser --unblock` 和 `scrape --unblocker` 是名称相近但功能不同的两项产品:`--unblock` 通过 `POST /unblock` 打开 Cloud Browser 会话,而 `--unblocker` 是在无状态的 `scrape` 或 `crawl` 上提供的反爬绕过功能。

**路径 D(交互式浏览器——持久化守护进程):** 在多次 CLI 调用之间保持一个 CDP 会话处于打开状态。Cookie、标签页和 AXTree 引用会在守护进程生命周期内持续存在。仅在执行 `start` 时需要 `--session`;后续调用会通过 `~/.scrapfly/sessions/.current` 自动解析会话。

```bash
scrapfly browser --session demo --session-timeout 1800 start &
scrapfly browser navigate https://web-scraping.dev/login
scrapfly browser wait 'input[name=username]' --visible
scrapfly browser fill 'input[name=username]' user123
scrapfly browser fill 'input[name=password]' password
scrapfly browser click 'button[type=submit]'
scrapfly browser content --raw > page.html         # fully rendered HTML
scrapfly browser eval 'document.body.innerText'
scrapfly browser close                             # daemon + remote release
使用 Scrapfly 自定义浏览器时,
fill
/
click
/
wait
/
slide
会自动使用 Antibot CDP domain,以模拟真人的操作时序;
content
使用 Page.getRenderedContent,并内联 iframe 内容。对于非 Scrapfly 浏览器,CLI 会回退到原始
Input.*
事件。
路径 E(LLM Agent):
scrapfly agent "<task>" --url <target>
会运行一个自主循环。模型负责选择工具调用(open、snapshot、click、fill、scroll、screenshot、eval、unblock、done),CLI 在 Browser 上执行这些调用,并将结果反馈给模型,直至模型调用
done
。
模型提供商可插拔:Anthropic(默认)、OpenAI、Gemini 或本地模型(Ollama/兼容 OpenAI 的服务)。基于 AXTree 的观察结果可以减少 token 消耗。
路径 F(仅使用 REST API): 跳过 CLI,直接调用
https://api.scrapfly.io/{scrape,screenshot,extraction,crawl}
,并附带
?key=<API_KEY>
。官方 SDK 支持 Python、TypeScript、Go 和 Rust。参见 docs.scrapfly.io。
路径 G(账户指标告警):
scrapfly alert ...
用于为 Scrapfly 监控指标(成功率、拦截率、错误数、成本、延迟等)定义阈值规则,并通过电子邮件、webhook 或应用内通知分发消息。该功能需要 Enterprise 套餐。
bash
undefined

Discover legal metrics

Discover legal metrics

scrapfly alert metric-families
scrapfly alert metric-families

Tune the threshold against the last 24h

Tune the threshold against the last 24h

scrapfly alert preview
--metric scrape.success_rate --comparator lt --threshold 95
--sustained-minutes 10 --range-minutes 1440
scrapfly alert preview
--metric scrape.success_rate --comparator lt --threshold 95
--sustained-minutes 10 --range-minutes 1440

Create

Create

scrapfly alert create
--name "Scrape Success Rate Low"
--metric scrape.success_rate --comparator lt --threshold 95
--sustained-minutes 10
--channel email:ops@example.com
--channel webhook:https://hooks.example.com/scrapfly

`alert list / get / update / snooze / unsnooze / test / delete / series
/ count-active` cover the rest of the lifecycle. Per-alert HMAC signing
keys are generated server-side and exposed via `alert get` for webhook
verification. Detailed reference: the
[scrapfly-alerting](../scrapfly-alerting/) skill.

**Path H (Scheduling recurring jobs):** `scrapfly schedule` plus the
per-product subgroups (`scrapfly scrape schedule`,
`scrapfly screenshot schedule`, `scrapfly crawl schedule`) define cron- or
interval-based recurring fires whose results are delivered to a webhook.

```bash
scrapfly alert create
--name "Scrape Success Rate Low"
--metric scrape.success_rate --comparator lt --threshold 95
--sustained-minutes 10
--channel email:ops@example.com
--channel webhook:https://hooks.example.com/scrapfly

`alert list / get / update / snooze / unsnooze / test / delete / series / count-active` 覆盖其余生命周期操作。每个告警的 HMAC 签名密钥均由服务器端生成,并通过 `alert get` 暴露,以便验证 webhook。详细参考:[scrapfly-alerting](../scrapfly-alerting/) skill。

**路径 H(调度定期任务):** `scrapfly schedule` 以及各产品子组(`scrapfly scrape schedule`、`scrapfly screenshot schedule`、`scrapfly crawl schedule`)可定义基于 cron 或时间间隔的定期触发,并将结果投递至 webhook。

```bash

Daily scrape schedule (config payload from a file, '-' for stdin)

Daily scrape schedule (config payload from a file, '-' for stdin)

scrapfly scrape schedule create --cron "0 6 * * *"
--webhook my-hook --config ./scrape.json
scrapfly scrape schedule create --cron "0 6 * * *"
--webhook my-hook --config ./scrape.json

Interval schedule with an inline payload

Interval schedule with an inline payload

scrapfly crawl schedule create --interval 6 --unit hour
--webhook my-hook --config-inline '{"url":"https://example.com"}'
scrapfly crawl schedule create --interval 6 --unit hour
--webhook my-hook --config-inline '{"url":"https://example.com"}'

Cross-product lifecycle (top-level group)

Cross-product lifecycle (top-level group)

scrapfly schedule list [--status ACTIVE|PAUSED|CANCELLED] scrapfly schedule get <id> scrapfly schedule update <id> --set-recurrence --cron "0 */2 * * *" scrapfly schedule pause <id> # / resume <id> scrapfly schedule execute <id> # fire now, ignoring next_scheduled_date scrapfly schedule delete <id> # terminal, cannot be resumed

`--webhook` is required (it's where each fire's result lands).
`--cron` wins over `--interval`/`--unit`. `--retry-on-failure
--max-retries N` (0..3) and `--allow-concurrency` tune fire behavior.

**Path I (BYOP Exit Peer):** `scrapfly exit-peer` installs and runs the
Bring-Your-Own-Proxy connector that routes Scrapfly traffic through your
own network egress over an mTLS tunnel.

```bash
scrapfly exit-peer install            # download binary + per-customer cert bundle
scrapfly exit-peer run --name lab-01  # run the connector in the foreground
scrapfly exit-peer status             # local install state + cert lifetime
Install dir defaults to
$SCRAPFLY_BYOP_DIR
or
$HOME/.scrapfly/byop
.
scrapfly schedule list [--status ACTIVE|PAUSED|CANCELLED] scrapfly schedule get <id> scrapfly schedule update <id> --set-recurrence --cron "0 */2 * * *" scrapfly schedule pause <id> # / resume <id> scrapfly schedule execute <id> # fire now, ignoring next_scheduled_date scrapfly schedule delete <id> # terminal, cannot be resumed

`--webhook` 为必填项,每次触发的结果都会传送到该地址。`--cron` 的优先级高于 `--interval`/`--unit`。可通过 `--retry-on-failure --max-retries N`(0..3)和 `--allow-concurrency` 调整触发行为。

**路径 I(BYOP Exit Peer):** `scrapfly exit-peer` 用于安装并运行 Bring-Your-Own-Proxy 连接器,将 Scrapfly 流量通过自有网络出口和 mTLS 隧道进行路由。

```bash
scrapfly exit-peer install            # download binary + per-customer cert bundle
scrapfly exit-peer run --name lab-01  # run the connector in the foreground
scrapfly exit-peer status             # local install state + cert lifetime
安装目录默认为
$SCRAPFLY_BYOP_DIR
或
$HOME/.scrapfly/byop
。

Authentication

身份验证

Set once:
bash
export SCRAPFLY_API_KEY=scp-live-...
设置一次即可:
bash
export SCRAPFLY_API_KEY=scp-live-...

or, persisted:

or, persisted:

scrapfly config set-key scp-live-...
scrapfly config set-key scp-live-...

interactive (opens a browser to mint a key):

interactive (opens a browser to mint a key):

scrapfly auth login # / logout / whoami

Resolution order: `--api-key` flag > `SCRAPFLY_API_KEY` env >
`~/.scrapfly/config.json`. Dev / self-hosted stacks: `--host` and
`--browser-host`, or `SCRAPFLY_API_HOST` / `SCRAPFLY_BROWSER_HOST`.

`scrapfly status` prints CLI version + auth state + account usage in one
call; `scrapfly account` shows plan, quota and subscription usage.

LLM providers for `agent` mode use their own env vars:
`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, or `OLLAMA_HOST`.
The CLI auto-detects the first one set.
scrapfly auth login # / logout / whoami

解析顺序:`--api-key` 参数 > `SCRAPFLY_API_KEY` 环境变量 > `~/.scrapfly/config.json`。对于开发/自托管部署,可使用 `--host` 和 `--browser-host`,或 `SCRAPFLY_API_HOST`/`SCRAPFLY_BROWSER_HOST`。

`scrapfly status` 一次调用即可打印 CLI 版本、身份验证状态和账户用量;`scrapfly account` 显示套餐、配额和订阅用量。

`agent` 模式下的 LLM 提供商使用各自的环境变量:

`ANTHROPIC_API_KEY`、`OPENAI_API_KEY`、`GEMINI_API_KEY` 或 `OLLAMA_HOST`。

CLI 会自动检测其中首个已设置的变量。

Output contract (for LLMs)

输出约定(面向 LLM)

All commands emit a stable JSON envelope on stdout:
json
{"success": true,  "product": "scrape", "data": { ... }}
{"success": false, "product": "scrape", "error": {"code": "...", "message": "...", "http_status": 422}}
Exit code is
0
on success,
1
on any error.
--pretty
swaps JSON for a one-line human summary. Binary products (screenshots, crawl artifacts, session recordings) require
-o <file>
or
-O <dir>
for the path; without either, JSON mode returns base64.
browser content --raw
prints the HTML body directly to stdout with no envelope (handy for pipes).
所有命令都会在 stdout 上输出稳定的 JSON 信封:
json
{"success": true,  "product": "scrape", "data": { ... }}
{"success": false, "product": "scrape", "error": {"code": "...", "message": "...", "http_status": 422}}
成功时退出码为
0
,发生任何错误时为
1
。
--pretty
会将 JSON 替换为单行人类可读摘要。对于二进制产品(截图、爬取工件、会话录制),必须使用
-o <file>
或
-O <dir>
指定路径;两者均未提供时,JSON 模式会返回 base64。
browser content --raw
会直接将 HTML 正文打印到 stdout,不带信封,便于通过管道处理。

Browser session reference

Browser 会话参考

Lifecycle

生命周期

CommandPurpose
browser --session <id> start [--url <target> --unblock]
Start daemon; foreground, background it with
&
browser status
Print pid, ws_url, alive
browser stop
Shut down daemon only (remote session lives until timeout)
browser close
Shut down daemon and release Scrapfly's remote browser immediately
命令用途
browser --session <id> start [--url <target> --unblock]
启动守护进程;可使用
&
放到后台
browser status
打印 pid、ws_url、alive
browser stop
仅关闭守护进程;远程会话会持续到超时
browser close
关闭守护进程并立即释放 Scrapfly 远程浏览器

Actions (sent to the daemon;
--session
optional once
start
has run)

操作(发送到守护进程;执行过
start
后,
--session
为可选参数)

CommandNotes
browser navigate <url>
Page.navigate + wait for load
browser snapshot
AXTree with refs (
e1
,
e2
, …) +
ax_node_id
+
backend_node_id
browser click <locator>
Antibot.clickOn on CSS/XPath/axNodeId; raw click for refs
browser fill <locator> <value> [--clear --wpm N]
Antibot.fill on CSS/XPath/axNodeId; Input.insertText for refs
browser click-ai <description>
Resolve the target from a natural-language description via the LLM, then click
browser fill-ai <description> <value>
Resolve the target via the LLM, then fill
browser wait <selector> [--visible --timeout-ms N]
Antibot.waitForElement (native, no JS poll)
browser slide <source> --target <sel> | --distance <px>
Antibot.clickAndSlide (slider captchas)
browser scroll <direction> [--amount px --ref e3]
Input wheel event
browser screenshot [--fullpage]
PNG via Page.captureScreenshot; use
-o/-O
for the file
browser content [--raw] [--skip-iframes]
Page.getRenderedContent - HTML with iframes inlined
browser eval <js>
Runtime.evaluate with awaitPromise
命令说明
browser navigate <url>
Page.navigate + 等待加载完成
browser snapshot
包含引用(
e1
、
e2
等)的 AXTree,以及
ax_node_id
+
backend_node_id
browser click <locator>
对 CSS/XPath/axNodeId 使用 Antibot.clickOn;对引用使用原始 click
browser fill <locator> <value> [--clear --wpm N]
对 CSS/XPath/axNodeId 使用 Antibot.fill;对引用使用 Input.insertText
browser click-ai <description>
通过 LLM 根据自然语言描述解析目标,然后点击
browser fill-ai <description> <value>
通过 LLM 解析目标,然后填写
browser wait <selector> [--visible --timeout-ms N]
Antibot.waitForElement(原生实现,不使用 JS 轮询)
browser slide <source> --target <sel> | --distance <px>
Antibot.clickAndSlide(滑块验证码)
browser scroll <direction> [--amount px --ref e3]
Input wheel 事件
browser screenshot [--fullpage]
通过 Page.captureScreenshot 生成 PNG;使用
-o/-O
指定文件
browser content [--raw] [--skip-iframes]
Page.getRenderedContent——内联 iframe 的 HTML
browser eval <js>
Runtime.evaluate,并启用 awaitPromise

Locators

定位器

click
/
fill
accept any of:
  • AXTree ref -
    e3
    , taken from the last
    snapshot
    . Uses raw
    Input.*
    path.
  • CSS selector (default) -
    input[name=username]
  • XPath -
    //button[text()="Submit"]
    with
    --selector-type xpath
  • AX node id -
    42
    from snapshot's
    ax_node_id
    field with
    --selector-type axNodeId
  • AI description -
    ai:<plain English>
    (or the
    click-ai
    /
    fill-ai
    shortcuts) lets an LLM resolve the ref from the live snapshot.
For CSS/XPath/axNodeId the CLI goes through Antibot on Scrapfly's browser.
click
/
fill
接受以下任意一种定位方式:
  • AXTree 引用——例如
    e3
    ,取自最近一次
    snapshot
    。使用原始
    Input.*
    路径。
  • CSS selector(默认)——例如
    input[name=username]
  • XPath——例如
    //button[text()="Submit"]
    ,需配合
    --selector-type xpath
  • AX node id——例如
    42
    ,取自 snapshot 的
    ax_node_id
    字段,需配合
    --selector-type axNodeId
  • AI 描述——例如
    ai:<plain English>
    (也可使用
    click-ai
    /
    fill-ai
    快捷方式),让 LLM 根据实时 snapshot 解析引用。
对于 CSS/XPath/axNodeId,CLI 会通过 Antibot 在 Scrapfly 浏览器上执行操作。

Recordings, extensions

录制与扩展

CommandPurpose
browser list
List active Browser sessions on the account
browser video <run-id>
Download the session recording (webm); needs
-o
/
-O
browser playback <run-id>
Fetch playback metadata for a debug run
browser extensions list | get <id> | upload <path> | delete <id>
Manage account browser extensions (
.zip
/
.crx
)
命令用途
browser list
列出账户中活动的 Browser 会话
browser video <run-id>
下载会话录制文件(webm);需要
-o
/
-O
browser playback <run-id>
获取调试运行的回放元数据
browser extensions list | get <id> | upload <path> | delete <id>
管理账户浏览器扩展(
.zip
/
.crx
)

Human takeover (VNC / WebRTC) and credential vault

人工接管(VNC/WebRTC)与凭据保险库

These flags work on
browser
,
browser start
, and
browser execute
:
FlagPurpose
--vault NAME --vault-key B64KEY
Attach a credential vault; items are decrypted and pushed over CDP before the session yields. The key is yours alone, Scrapfly never stores it, and omitting it fails the session with
ERR::BROWSER::VAULT_KEY_INVALID
--enable-vnc --vnc-password PW
Expose the session over VNC so a human can take over
--enable-rtc --rtc-password PW [--rtc-username U]
Expose the session over WebRTC live video (username defaults to
scrapfly
)
--hitl-allowed-network IP|CIDR
Trust a source range to attach with no credentials (repeatable). This REPLACES the password requirement, it does not add to it, and the server then generates its own secret
browser salt
Print the project salt,
sha256(api_key)[:8]
Which VNC password a viewer types depends on the endpoint. Scrapfly prefixes your project salt at allocation, and the two endpoints check it differently:
EndpointPassword to type
Native client on the TCP mux,
vnc://<run_id>@<host>:5901
<project_salt>-<vnc_password>
WebSocket,
wss://<host>/run/<run_id>/vnc
the raw
<vnc_password>
The mux keys its DES challenge on the salted form (native clients do not strip it), so two customers who pick the same password never collide; the WebSocket handler strips the salt server-side before the same check.
browser start
prints the TCP URL and the salted password that goes with it:
bash
scrapfly browser --session demo --enable-vnc --vnc-password hunter2 start &
以下参数适用于
browser
、
browser start
和
browser execute
:
参数用途
--vault NAME --vault-key B64KEY
附加凭据保险库;会话移交前,其中的项目会被解密并通过 CDP 推送。密钥仅由你保管,Scrapfly 绝不会存储;如果省略密钥,会话将因
ERR::BROWSER::VAULT_KEY_INVALID
而失败
--enable-vnc --vnc-password PW
通过 VNC 公开会话,以便人工接管
--enable-rtc --rtc-password PW [--rtc-username U]
通过 WebRTC 公开实时视频会话(用户名默认为
scrapfly
)
--hitl-allowed-network IP|CIDR
信任指定源地址范围,使其无需凭据即可接入(可重复使用)。该参数会取代密码要求,而不是在密码要求之外追加;服务器随后会生成自己的 secret
browser salt
打印项目 salt,即
sha256(api_key)[:8]
查看者需要输入的 VNC 密码取决于所使用的端点。 Scrapfly 在分配时会将项目 salt 添加到密码前缀中,而两个端点检查密码的方式不同:
端点需要输入的密码
TCP mux 上的原生客户端,
vnc://<run_id>@<host>:5901
<project_salt>-<vnc_password>
WebSocket,
wss://<host>/run/<run_id>/vnc
原始的
<vnc_password>
mux 使用加盐形式作为 DES challenge 的密钥(原生客户端不会移除 salt),因此两个选择相同密码的客户不会发生冲突;WebSocket 处理器会在执行相同检查前在服务器端移除 salt。
browser start
会打印 TCP URL 和与之对应的加盐密码:
bash
scrapfly browser --session demo --enable-vnc --vnc-password hunter2 start &

[session demo] vnc vnc://01K5Z.../@browser.scrapfly.io:5901

[session demo] vnc vnc://01K5Z.../@browser.scrapfly.io:5901

[session demo] vnc password <project_salt>-hunter2

[session demo] vnc password <project_salt>-hunter2


The `vnc://` username is the run id, which only exists once the session is
allocated, so `browser start` prints the URL after it connects. In ws mode
(`scrapfly browser --enable-vnc --vnc-password PW`) the JSON envelope carries
`project_salt`, `vnc_password` (salted), and `vnc_url` with a `{run_id}`
placeholder.

`vnc://` 用户名是 run id,只有会话完成分配后才会生成,因此 `browser start` 会在连接成功后打印 URL。在 ws 模式(`scrapfly browser --enable-vnc --vnc-password PW`)下,JSON 信封包含 `project_salt`、`vnc_password`(已加盐)以及带有 `{run_id}` 占位符的 `vnc_url`。

Crawler reference

Crawler 参考

Submit + poll

提交与轮询

CommandPurpose
crawl start <url>
Submit a crawl; print the UUID immediately
crawl run <url>
Submit + poll until DONE / FAILED / CANCELLED
crawl watch <uuid>
Live stats panel (visited/extracted/failed/skipped/queue/credits) until terminal
crawl status <uuid>
Fetch status; envelope exposes a top-level
terminal
field (
running|done|failed|cancelled
) for shell scripting
crawl urls <uuid> --status visited|pending|failed|skipped
Stream discovered URLs (paginated)
crawl contents <uuid> --format markdown [--url URL --plain]
Bulk JSON or single-URL plain body
crawl contents-batch <uuid> <url...> [--from-file F] --format markdown
One round-trip for up to 100 URLs
crawl cancel <uuid>
Stop a running crawl
crawl artifact <uuid> --type warc|har -o file
Download the recording
命令用途
crawl start <url>
提交爬取任务;立即打印 UUID
crawl run <url>
提交并轮询,直至 DONE/FAILED/CANCELLED
crawl watch <uuid>
实时统计面板,显示已访问/已提取/失败/跳过/队列/credits,直至任务结束
crawl status <uuid>
获取状态;信封暴露顶层
terminal
字段(
running|done|failed|cancelled
),便于编写 shell 脚本
crawl urls <uuid> --status visited|pending|failed|skipped
流式输出发现的 URL(分页)
crawl contents <uuid> --format markdown [--url URL --plain]
批量 JSON 或单个 URL 的纯正文
crawl contents-batch <uuid> <url...> [--from-file F] --format markdown
单次往返最多获取 100 个 URL
crawl cancel <uuid>
停止正在运行的爬取任务
crawl artifact <uuid> --type warc|har -o file
下载录制文件

Flags on
crawl start
/
crawl run

crawl start
/
crawl run
的参数

Every documented
CrawlerConfig
field is exposed:
FlagMaps to
--max-pages N
page_limit
--max-depth N
max_depth
--max-duration N
max_duration
(seconds, 15-10800)
--max-api-credit N
max_api_credit
--exclude PATH
/
--include PATH
exclude_paths
/
include_only_paths
(repeatable, mutually exclusive)
--ignore-base-path
ignore_base_path_restriction
--follow-external
/
--allowed-external-domain D
follow_external_links
/
allowed_external_domains
--follow-internal-subdomains true|false
(tri-state) /
--allowed-internal-subdomain D
matching fields
--header k=v
(repeatable)
headers
--delay MS
/
--user-agent UA
/
--max-concurrency N
/
--rendering-delay MS
request shape
--use-sitemaps
/
--ignore-no-follow
/
--respect-robots-txt true|false
strategy
--cache
/
--cache-ttl S
/
--cache-clear
caching
--content-format F
(repeatable) /
--extraction-rules-file PATH
content + extraction
--unblocker
/
--proxy-pool P
/
--country CC
scraping options
--webhook NAME
/
--webhook-event E
(repeatable)
webhooks
所有已记录的
CrawlerConfig
字段均已开放:
参数映射到
--max-pages N
page_limit
--max-depth N
max_depth
--max-duration N
max_duration
(秒,15-10800)
--max-api-credit N
max_api_credit
--exclude PATH
/
--include PATH
exclude_paths
/
include_only_paths
(可重复使用,二者互斥)
--ignore-base-path
ignore_base_path_restriction
--follow-external
/
--allowed-external-domain D
follow_external_links
/
allowed_external_domains
--follow-internal-subdomains true|false
(三态)/
--allowed-internal-subdomain D
对应匹配字段
--header k=v
(可重复使用)
headers
--delay MS
/
--user-agent UA
/
--max-concurrency N
/
--rendering-delay MS
请求配置
--use-sitemaps
/
--ignore-no-follow
/
--respect-robots-txt true|false
策略
--cache
/
--cache-ttl S
/
--cache-clear
缓存
--content-format F
(可重复使用)/
--extraction-rules-file PATH
内容与提取
--unblocker
/
--proxy-pool P
/
--country CC
抓取选项
--webhook NAME
/
--webhook-event E
(可重复使用)
Webhook

Read from a WARC / HAR artifact

从 WARC/HAR 工件读取

bash
scrapfly crawl artifact <uuid> --type warc -o crawl.warc
scrapfly crawl parse warc-list crawl.warc --pretty             # URLs + statuses
scrapfly crawl parse warc-get crawl.warc https://example.com \
  --raw > page.html                                             # body straight to stdout

scrapfly crawl artifact <uuid> --type har -o crawl.har
scrapfly crawl parse har-list crawl.har --pretty               # request table
scrapfly crawl parse har-get crawl.har https://example.com/api \
  --raw | jq .                                                  # extract one response
-
as the file path reads from stdin, so you can pipe straight from
crawl artifact -o -
.
bash
scrapfly crawl artifact <uuid> --type warc -o crawl.warc
scrapfly crawl parse warc-list crawl.warc --pretty             # URLs + statuses
scrapfly crawl parse warc-get crawl.warc https://example.com \
  --raw > page.html                                             # body straight to stdout

scrapfly crawl artifact <uuid> --type har -o crawl.har
scrapfly crawl parse har-list crawl.har --pretty               # request table
scrapfly crawl parse har-get crawl.har https://example.com/api \
  --raw | jq .                                                  # extract one response
将
-
作为文件路径会从 stdin 读取,因此可以直接使用
crawl artifact -o -
通过管道传输。

Core API Endpoints

核心 API 端点

ProductEndpointCLI
Web Scraping
GET/POST /scrape
scrapfly scrape <url>
Screenshot
POST /screenshot
scrapfly screenshot <url>
Extraction
POST /extraction
scrapfly extract
Crawler
POST /crawl
+
/crawl/{uuid}/{status,urls,contents,artifact}
scrapfly crawl {start,run,status,urls,contents,cancel,artifact}
Browser (CDP)
wss://browser.scrapfly.io?api_key=...
scrapfly browser
Browser Unblock
POST /unblock
scrapfly browser <url> --unblock
Browser Session Stop
POST /session/{id}/stop
scrapfly browser close
Session Recording
GET /run/{id}/video
scrapfly browser video <run-id>
Feedback
POST /dashboard/api/feedback
(on
scrapfly.io
, not the API host)
scrapfly feedback
产品端点CLI
网页抓取
GET/POST /scrape
scrapfly scrape <url>
屏幕截图
POST /screenshot
scrapfly screenshot <url>
数据提取
POST /extraction
scrapfly extract
Crawler
POST /crawl
+
/crawl/{uuid}/{status,urls,contents,artifact}
scrapfly crawl {start,run,status,urls,contents,cancel,artifact}
Browser(CDP)
wss://browser.scrapfly.io?api_key=...
scrapfly browser
Browser Unblock
POST /unblock
scrapfly browser <url> --unblock
Browser Session Stop
POST /session/{id}/stop
scrapfly browser close
会话录制
GET /run/{id}/video
scrapfly browser video <run-id>
反馈
POST /dashboard/api/feedback
(位于
scrapfly.io
,不是 API host)
scrapfly feedback

Quick examples

快速示例

bash
undefined
bash
undefined

Scrape a JS-heavy page with the unblocker and markdown output

Scrape a JS-heavy page with the unblocker and markdown output

scrapfly scrape https://web-scraping.dev/products --render-js --unblocker --format markdown
scrapfly scrape https://web-scraping.dev/products --render-js --unblocker --format markdown

Scrape many URLs in parallel (ndjson on stdout, one envelope per line)

Scrape many URLs in parallel (ndjson on stdout, one envelope per line)

Or feed URLs from a file

Or feed URLs from a file

scrapfly scrape --from-file urls.txt --format markdown | jq -c '.data.result.url'
scrapfly scrape --from-file urls.txt --format markdown | jq -c '.data.result.url'

Pipe scrape body straight into AI extraction

Pipe scrape body straight into AI extraction

scrapfly scrape https://web-scraping.dev/product/1 --render-js --proxified
| scrapfly extract --content-type text/html --prompt "name, price, sku"
scrapfly scrape https://web-scraping.dev/product/1 --render-js --proxified
| scrapfly extract --content-type text/html --prompt "name, price, sku"

Screenshot into an auto-named file in a directory

Screenshot into an auto-named file in a directory

scrapfly -O ./shots screenshot https://example.com --resolution 1920x1080
scrapfly -O ./shots screenshot https://example.com --resolution 1920x1080

Crawl synchronously with markdown content streaming

Crawl synchronously with markdown content streaming

scrapfly crawl run https://example.com --max-pages 20 --content-format markdown
scrapfly crawl run https://example.com --max-pages 20 --content-format markdown

Multi-call browser session: log in, dump rendered HTML, clean up

Multi-call browser session: log in, dump rendered HTML, clean up

scrapfly browser --session demo --session-timeout 1800 start & scrapfly browser navigate https://web-scraping.dev/login scrapfly browser wait 'input[name=username]' --visible scrapfly browser fill 'input[name=username]' user123 --wpm 280 scrapfly browser fill 'input[name=password]' password scrapfly browser click 'button[type=submit]' scrapfly browser content --raw > after-login.html scrapfly browser close
scrapfly browser --session demo --session-timeout 1800 start & scrapfly browser navigate https://web-scraping.dev/login scrapfly browser wait 'input[name=username]' --visible scrapfly browser fill 'input[name=username]' user123 --wpm 280 scrapfly browser fill 'input[name=password]' password scrapfly browser click 'button[type=submit]' scrapfly browser content --raw > after-login.html scrapfly browser close

Hand a Scrapfly-unblocked CDP URL to browser-use

Hand a Scrapfly-unblocked CDP URL to browser-use

WS=$(scrapfly browser https://target.example.com --unblock --country us --pretty | jq -r .ws_url) python examples/browser-use-with-scrapfly.py # reads WS from scrapfly CLI
WS=$(scrapfly browser https://target.example.com --unblock --country us --pretty | jq -r .ws_url) python examples/browser-use-with-scrapfly.py # reads WS from scrapfly CLI

LLM agent with structured output

LLM agent with structured output

ANTHROPIC_API_KEY=... scrapfly agent "Name and price of the first product"
--url https://web-scraping.dev/products
--schema '{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"string"}},"required":["name","price"]}'
undefined
ANTHROPIC_API_KEY=... scrapfly agent "Name and price of the first product"
--url https://web-scraping.dev/products
--schema '{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"string"}},"required":["name","price"]}'
undefined

Reporting product feedback

报告产品反馈

scrapfly feedback
files a report about a Scrapfly surface - the CLI, an API, the docs, the dashboard, the MCP server, a skill - from the terminal. It lands in the same store the dashboard feedback widget writes to, which is where the team reads reports. It is not support: no ticket is opened and no reply comes back, so an account or integration problem still goes to https://scrapfly.io/dashboard/support.
bash
scrapfly feedback --sentiment negative --feature crawler_api \
  --message "crawl status returned 200 with an empty urls array for ten minutes after the crawl finished" \
  --context "Mirroring a 300-page docs site, polling crawl status every 15s, CLI 0.4.1"
If you are an agent driving this CLI: when a Scrapfly surface was useful, confusing, wrong, or incomplete during a session, draft one report at the end of the session, once the user's task is done. Show them the draft and file it only if they agree - it goes out on their API key and carries their account.
  • --sentiment negative
    a defect or blocker stopped a command from working;
    neutral
    friction or a workaround, but the task completed;
    positive
    it worked, or a step behaved better than expected. File positive reports too.
  • --message
    names the command and what it did,
    --context
    the goal and the CLI version. Both are 10-2000 characters, and
    --message
    needs five words: "it broke" is not a report anyone can act on.
  • --feature
    scopes the report to a product area. An unknown value is rejected with the full list, so you can correct it from the error.
  • --actor
    defaults to
    agent
    when a coding-agent environment variable is present,
    human
    otherwise. Pass
    --actor human
    when you are relaying the user's own words, and keep their wording.
  • Report the product, not your own environment, not the model's behaviour, not a prompt you found unclear, and not a tool error you recovered from on the next call.
  • A failed submission is never a reason to fail, stall or retry the task that produced it. On
    429
    the account's hourly budget is spent: drop the report. On any other error, show the drafted
    --message
    and
    --context
    so the user can file it by hand.
scrapfly feedback
可从终端提交有关 Scrapfly 各个产品界面的报告,包括 CLI、API、文档、dashboard、MCP server 或 skill。报告会进入与 dashboard 反馈组件相同的存储位置,团队会在那里查看报告。它不是支持工单:不会创建 ticket,也不会收到回复。因此,如果账户或集成仍存在问题,请前往 https://scrapfly.io/dashboard/support。
bash
scrapfly feedback --sentiment negative --feature crawler_api \
  --message "crawl status returned 200 with an empty urls array for ten minutes after the crawl finished" \
  --context "Mirroring a 300-page docs site, polling crawl status every 15s, CLI 0.4.1"
如果你是驱动此 CLI 的 Agent:当某个 Scrapfly 产品界面在会话期间表现出有用、令人困惑、错误或不完整的行为时,应在会话结束时、用户任务完成之后起草一份报告。向用户展示草稿,仅在用户同意时提交;报告会使用你的 API key 发出,并与你的账户关联。
  • --sentiment negative
    表示缺陷或阻塞因素导致命令无法工作;
    neutral
    表示任务已完成,但遇到了阻力或需要变通;
    positive
    表示运行成功,或某个步骤的表现优于预期。正面报告也应提交。
  • --message
    应说明命令及其行为,
    --context
    应说明目标和 CLI 版本。两者长度均为 10-2000 个字符,且
    --message
    至少需要五个单词:“it broke”并不是任何人都能据此采取行动的报告。
  • --feature
    用于将报告限定到特定产品领域。如果传入未知值,命令会拒绝执行并返回完整列表,便于你根据错误进行修正。
  • 存在 coding-agent 环境变量时,
    --actor
    默认为
    agent
    ,否则默认为
    human
    。转述用户自己的话时应传入
    --actor human
    ,并保留用户的原始措辞。
  • 应报告产品本身,而不是你的环境、模型行为、你认为表述不清晰的 prompt,或你在下一次调用中已经恢复的工具错误。
  • 提交失败绝不构成失败、停滞或重试产生该反馈的任务的理由。遇到
    429
    时,账户的小时预算已经耗尽,应放弃报告。遇到其他错误时,应展示已起草的
    --message
    和
    --context
    ,以便用户手动提交。

Shell completion

Shell 补全

Cobra ships completion scripts for bash, zsh, fish, and PowerShell. Install once:
bash
undefined
Cobra 提供适用于 bash、zsh、fish 和 PowerShell 的补全脚本。安装一次即可:
bash
undefined

zsh

zsh

scrapfly completion zsh > "${fpath[1]}/_scrapfly"
scrapfly completion zsh > "${fpath[1]}/_scrapfly"

bash

bash

scrapfly completion bash > /etc/bash_completion.d/scrapfly # or ~/.bash_completion.d/
scrapfly completion bash > /etc/bash_completion.d/scrapfly # or ~/.bash_completion.d/

fish

fish

scrapfly completion fish > ~/.config/fish/completions/scrapfly.fish
undefined
scrapfly completion fish > ~/.config/fish/completions/scrapfly.fish
undefined

MCP server

MCP server

scrapfly mcp serve
exposes
scrape
,
screenshot
,
extract
,
crawl_run
, and
selector
as MCP tools over stdio. Add the binary to a compatible client (Claude Desktop, Cursor, Claude Code):
jsonc
{
  "mcpServers": {
    "scrapfly": {
      "command": "scrapfly",
      "args": ["mcp", "serve"],
      "env": { "SCRAPFLY_API_KEY": "scp-live-..." }
    }
  }
}
Selector discovery also works from inside the agent loop via the
find_selector
tool - useful when the model wants to produce a durable CSS selector instead of relying on per-snapshot refs.
scrapfly mcp serve
通过 stdio 将
scrape
、
screenshot
、
extract
、
crawl_run
和
selector
暴露为 MCP 工具。将二进制文件添加到兼容客户端中(Claude Desktop、Cursor、Claude Code):
jsonc
{
  "mcpServers": {
    "scrapfly": {
      "command": "scrapfly",
      "args": ["mcp", "serve"],
      "env": { "SCRAPFLY_API_KEY": "scp-live-..." }
    }
  }
}
在 Agent 循环中,也可以通过
find_selector
工具发现选择器。当模型希望生成稳定的 CSS selector,而不是依赖每次 snapshot 中的临时引用时,该功能非常有用。

Reference

参考