scrapfly-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseScrapfly: 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, , 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.
scrapflyScrapfly 通过五项产品让 AI Agent 和应用程序能够访问 Web:网页抓取、屏幕截图、AI 数据提取、递归爬取,以及可直接通过 CDP 驱动、通过持久化会话守护进程使用,或交给 LLM Agent 使用的远程浏览器。
此 CLI 是上述五项产品以及一种 Playwright-MCP 风格 Agent 模式的统一入口。默认使用 JSON 通信,因此 LLM 调用方可以直接通过管道传入。
scrapflyInstallation
安装
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@latestSix Usage Paths
六条使用路径
Path A (Fetch content): - the default. Covers
every field from the SDK:
scrapfly scrape <url>ScrapeConfig- Render & navigate: ,
--render-js,--wait-for-selector,--rendering-wait,--rendering-stage,--auto-scroll,--js-file FILE--js-scenario-file FILE - Anti-bot: (
--unblockeris the deprecated alias and still works),--asp,--cost-budget N,--proxy-pool,--country--geolocation - Format & extraction: +
--format markdown|clean_html|text|raw;--format-option,--extraction-prompt,--extraction-model,--extraction-template(ephemeral inline template)--extraction-template-file FILE - Request shape: ,
--method,--header k=v,--cookie n=v,--body,--body-file(structured body as JSON map),--data-file FILE,--lang,--os--browser-brand - Sessions & caching: ,
--session,--session-sticky-proxy,--cache,--cache-ttl N,--cache-clear--retry=true|false - Screenshots on scrape: (fullpage shortcut),
--screenshot(repeatable),--screenshot-named name=selector--screenshot-flag FLAG - Observability: ,
--debug,--ssl,--dns,--correlation-id,--tag,--webhook NAME--timing - Batch: multiple positional URLs or +
--from-file PATH|-(ndjson on stdout)--concurrency - Pipe-friendly: streams the raw upstream body with no JSON envelope
--proxified
Path B (Binary / structured outputs): dedicated commands for focused
products.
- - JPG (default), PNG, WebP or GIF of the page or a selector. Full
scrapfly screenshot <url>surface:ScreenshotConfig,--format,--capture,--resolution,--country,--option,--wait-for-selector,--rendering-wait,--auto-scroll,--js-file,--cache,--cache-ttl,--cache-clear,--webhook.--vision-deficiency - - run AI/template extraction on a document you already fetched. Full
scrapfly extract --file page.html --prompt "...": body viaExtractionConfigor stdin;--file,--content-type,--url,--charset(one of four extraction modes),--prompt | --model | --template | --template-file,--compression,--webhook.--request-timeout - - recursive crawls with status polling, content streaming, WARC/HAR artifacts. Post-download:
scrapfly crawl run <url> --max-pages Nreads the artifact directly (no separate tooling). See the Crawler section below.crawl parse har-list|har-get|warc-list|warc-get
Path C (Interactive browser - one-shot): mint a CDP WebSocket URL to
hand to Playwright, Puppeteer, or :
browser-usebash
undefined路径 A(获取内容): ——默认方式。覆盖 SDK 中的每个 字段:
scrapfly scrape <url>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(以 JSON map 表示的结构化正文)、--data-file FILE、--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|-(在 stdout 上输出 ndjson)--concurrency - 便于管道处理:会直接流式输出原始上游正文,不带 JSON 信封
--proxified
路径 B(二进制/结构化输出): 多个专用命令用于聚焦各项产品。
- ——以 JPG(默认)、PNG、WebP 或 GIF 格式生成页面或选择器的图像。提供完整的
scrapfly screenshot <url>选项:ScreenshotConfig、--format、--capture、--resolution、--country、--option、--wait-for-selector、--rendering-wait、--auto-scroll、--js-file、--cache、--cache-ttl、--cache-clear、--webhook。--vision-deficiency - ——对已经获取的文档执行 AI/模板提取。提供完整的
scrapfly extract --file page.html --prompt "...":通过ExtractionConfig或 stdin 提供正文;支持--file、--content-type、--url、--charset(四种提取模式之一)、--prompt | --model | --template | --template-file、--compression、--webhook。--request-timeout - ——执行递归爬取,支持状态轮询、内容流式传输以及 WARC/HAR 工件。下载后可直接使用
scrapfly crawl run <url> --max-pages N读取工件,无需其他工具。详见下方 Crawler 部分。crawl parse har-list|har-get|warc-list|warc-get
路径 C(交互式浏览器——一次性): 生成 CDP WebSocket URL,以交给 Playwright、Puppeteer 或 :
browser-usebash
undefinedplain 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 releaseWhen running against Scrapfly's custom browser, / /
/ automatically use the Antibot CDP domain for
human-like timing; uses Page.getRenderedContent which
inlines iframe content. Against a non-Scrapfly browser, the CLI falls
back to raw events.
fillclickwaitslidecontentInput.*Path E (LLM agent): 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 .
Providers are pluggable: Anthropic (default), OpenAI, Gemini, or local
(Ollama / OpenAI-compatible). AXTree-based observations keep the token
budget small.
scrapfly agent "<task>" --url <target>donePath F (REST API only): skip the CLI, call
directly
with . Official SDKs: Python, TypeScript, Go, Rust. See
docs.scrapfly.io.
https://api.scrapfly.io/{scrape,screenshot,extraction,crawl}?key=<API_KEY>Path G (Alerting on account metrics): 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.
scrapfly alert ...bash
undefinedscrapfly 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 自定义浏览器时,/// 会自动使用 Antibot CDP domain,以模拟真人的操作时序; 使用 Page.getRenderedContent,并内联 iframe 内容。对于非 Scrapfly 浏览器,CLI 会回退到原始 事件。
fillclickwaitslidecontentInput.*路径 E(LLM Agent): 会运行一个自主循环。模型负责选择工具调用(open、snapshot、click、fill、scroll、screenshot、eval、unblock、done),CLI 在 Browser 上执行这些调用,并将结果反馈给模型,直至模型调用 。
scrapfly agent "<task>" --url <target>done模型提供商可插拔:Anthropic(默认)、OpenAI、Gemini 或本地模型(Ollama/兼容 OpenAI 的服务)。基于 AXTree 的观察结果可以减少 token 消耗。
路径 F(仅使用 REST API): 跳过 CLI,直接调用 ,并附带 。官方 SDK 支持 Python、TypeScript、Go 和 Rust。参见 docs.scrapfly.io。
https://api.scrapfly.io/{scrape,screenshot,extraction,crawl}?key=<API_KEY>路径 G(账户指标告警): 用于为 Scrapfly 监控指标(成功率、拦截率、错误数、成本、延迟等)定义阈值规则,并通过电子邮件、webhook 或应用内通知分发消息。该功能需要 Enterprise 套餐。
scrapfly alert ...bash
undefinedDiscover 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
--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
--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
--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.
```bashscrapfly 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
--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。
```bashDaily 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
--webhook my-hook --config ./scrape.json
scrapfly scrape schedule create --cron "0 6 * * *"
--webhook my-hook --config ./scrape.json
--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"}'
--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"}'
--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 lifetimeInstall dir defaults to or .
$SCRAPFLY_BYOP_DIR$HOME/.scrapfly/byopscrapfly 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/byopAuthentication
身份验证
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 on success, on any error. swaps JSON for a
one-line human summary. Binary products (screenshots, crawl artifacts,
session recordings) require or for the path; without
either, JSON mode returns base64. prints the HTML
body directly to stdout with no envelope (handy for pipes).
01--pretty-o <file>-O <dir>browser content --raw所有命令都会在 stdout 上输出稳定的 JSON 信封:
json
{"success": true, "product": "scrape", "data": { ... }}
{"success": false, "product": "scrape", "error": {"code": "...", "message": "...", "http_status": 422}}成功时退出码为 ,发生任何错误时为 。 会将 JSON 替换为单行人类可读摘要。对于二进制产品(截图、爬取工件、会话录制),必须使用 或 指定路径;两者均未提供时,JSON 模式会返回 base64。 会直接将 HTML 正文打印到 stdout,不带信封,便于通过管道处理。
01--pretty-o <file>-O <dir>browser content --rawBrowser session reference
Browser 会话参考
Lifecycle
生命周期
| Command | Purpose |
|---|---|
| Start daemon; foreground, background it with |
| Print pid, ws_url, alive |
| Shut down daemon only (remote session lives until timeout) |
| Shut down daemon and release Scrapfly's remote browser immediately |
| 命令 | 用途 |
|---|---|
| 启动守护进程;可使用 |
| 打印 pid、ws_url、alive |
| 仅关闭守护进程;远程会话会持续到超时 |
| 关闭守护进程并立即释放 Scrapfly 远程浏览器 |
Actions (sent to the daemon; --session
optional once start
has run)
--sessionstart操作(发送到守护进程;执行过 start
后,--session
为可选参数)
start--session| Command | Notes |
|---|---|
| Page.navigate + wait for load |
| AXTree with refs ( |
| Antibot.clickOn on CSS/XPath/axNodeId; raw click for refs |
| Antibot.fill on CSS/XPath/axNodeId; Input.insertText for refs |
| Resolve the target from a natural-language description via the LLM, then click |
| Resolve the target via the LLM, then fill |
| Antibot.waitForElement (native, no JS poll) |
| Antibot.clickAndSlide (slider captchas) |
| Input wheel event |
| PNG via Page.captureScreenshot; use |
| Page.getRenderedContent - HTML with iframes inlined |
| Runtime.evaluate with awaitPromise |
| 命令 | 说明 |
|---|---|
| Page.navigate + 等待加载完成 |
| 包含引用( |
| 对 CSS/XPath/axNodeId 使用 Antibot.clickOn;对引用使用原始 click |
| 对 CSS/XPath/axNodeId 使用 Antibot.fill;对引用使用 Input.insertText |
| 通过 LLM 根据自然语言描述解析目标,然后点击 |
| 通过 LLM 解析目标,然后填写 |
| Antibot.waitForElement(原生实现,不使用 JS 轮询) |
| Antibot.clickAndSlide(滑块验证码) |
| Input wheel 事件 |
| 通过 Page.captureScreenshot 生成 PNG;使用 |
| Page.getRenderedContent——内联 iframe 的 HTML |
| Runtime.evaluate,并启用 awaitPromise |
Locators
定位器
clickfill- AXTree ref - , taken from the last
e3. Uses rawsnapshotpath.Input.* - CSS selector (default) -
input[name=username] - XPath - with
//button[text()="Submit"]--selector-type xpath - AX node id - from snapshot's
42field withax_node_id--selector-type axNodeId - AI description - (or the
ai:<plain English>/click-aishortcuts) lets an LLM resolve the ref from the live snapshot.fill-ai
For CSS/XPath/axNodeId the CLI goes through Antibot on Scrapfly's browser.
clickfill- AXTree 引用——例如 ,取自最近一次
e3。使用原始snapshot路径。Input.* - CSS selector(默认)——例如
input[name=username] - XPath——例如 ,需配合
//button[text()="Submit"]--selector-type xpath - AX node id——例如 ,取自 snapshot 的
42字段,需配合ax_node_id--selector-type axNodeId - AI 描述——例如 (也可使用
ai:<plain English>/click-ai快捷方式),让 LLM 根据实时 snapshot 解析引用。fill-ai
对于 CSS/XPath/axNodeId,CLI 会通过 Antibot 在 Scrapfly 浏览器上执行操作。
Recordings, extensions
录制与扩展
| Command | Purpose |
|---|---|
| List active Browser sessions on the account |
| Download the session recording (webm); needs |
| Fetch playback metadata for a debug run |
| Manage account browser extensions ( |
| 命令 | 用途 |
|---|---|
| 列出账户中活动的 Browser 会话 |
| 下载会话录制文件(webm);需要 |
| 获取调试运行的回放元数据 |
| 管理账户浏览器扩展( |
Human takeover (VNC / WebRTC) and credential vault
人工接管(VNC/WebRTC)与凭据保险库
These flags work on , , and :
browserbrowser startbrowser execute| Flag | Purpose |
|---|---|
| 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 |
| Expose the session over VNC so a human can take over |
| Expose the session over WebRTC live video (username defaults to |
| 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 |
| Print the project salt, |
Which VNC password a viewer types depends on the endpoint. Scrapfly prefixes
your project salt at allocation, and the two endpoints check it differently:
| Endpoint | Password to type |
|---|---|
Native client on the TCP mux, | |
WebSocket, | the raw |
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.
prints the TCP URL and the salted password that goes with it:
browser startbash
scrapfly browser --session demo --enable-vnc --vnc-password hunter2 start &以下参数适用于 、 和 :
browserbrowser startbrowser execute| 参数 | 用途 |
|---|---|
| 附加凭据保险库;会话移交前,其中的项目会被解密并通过 CDP 推送。密钥仅由你保管,Scrapfly 绝不会存储;如果省略密钥,会话将因 |
| 通过 VNC 公开会话,以便人工接管 |
| 通过 WebRTC 公开实时视频会话(用户名默认为 |
| 信任指定源地址范围,使其无需凭据即可接入(可重复使用)。该参数会取代密码要求,而不是在密码要求之外追加;服务器随后会生成自己的 secret |
| 打印项目 salt,即 |
查看者需要输入的 VNC 密码取决于所使用的端点。 Scrapfly 在分配时会将项目 salt 添加到密码前缀中,而两个端点检查密码的方式不同:
| 端点 | 需要输入的密码 |
|---|---|
TCP mux 上的原生客户端, | |
WebSocket, | 原始的 |
mux 使用加盐形式作为 DES challenge 的密钥(原生客户端不会移除 salt),因此两个选择相同密码的客户不会发生冲突;WebSocket 处理器会在执行相同检查前在服务器端移除 salt。 会打印 TCP URL 和与之对应的加盐密码:
browser startbash
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
提交与轮询
| Command | Purpose |
|---|---|
| Submit a crawl; print the UUID immediately |
| Submit + poll until DONE / FAILED / CANCELLED |
| Live stats panel (visited/extracted/failed/skipped/queue/credits) until terminal |
| Fetch status; envelope exposes a top-level |
| Stream discovered URLs (paginated) |
| Bulk JSON or single-URL plain body |
| One round-trip for up to 100 URLs |
| Stop a running crawl |
| Download the recording |
| 命令 | 用途 |
|---|---|
| 提交爬取任务;立即打印 UUID |
| 提交并轮询,直至 DONE/FAILED/CANCELLED |
| 实时统计面板,显示已访问/已提取/失败/跳过/队列/credits,直至任务结束 |
| 获取状态;信封暴露顶层 |
| 流式输出发现的 URL(分页) |
| 批量 JSON 或单个 URL 的纯正文 |
| 单次往返最多获取 100 个 URL |
| 停止正在运行的爬取任务 |
| 下载录制文件 |
Flags on crawl start
/ crawl run
crawl startcrawl runcrawl start
/crawl run
的参数
crawl startcrawl runEvery documented field is exposed:
CrawlerConfig| Flag | Maps to |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| matching fields |
| |
| request shape |
| strategy |
| caching |
| content + extraction |
| scraping options |
| webhooks |
所有已记录的 字段均已开放:
CrawlerConfig| 参数 | 映射到 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| 对应匹配字段 |
| |
| 请求配置 |
| 策略 |
| 缓存 |
| 内容与提取 |
| 抓取选项 |
| 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-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 端点
| Product | Endpoint | CLI |
|---|---|---|
| Web Scraping | | |
| Screenshot | | |
| Extraction | | |
| Crawler | | |
| Browser (CDP) | | |
| Browser Unblock | | |
| Browser Session Stop | | |
| Session Recording | | |
| Feedback | | |
| 产品 | 端点 | CLI |
|---|---|---|
| 网页抓取 | | |
| 屏幕截图 | | |
| 数据提取 | | |
| Crawler | | |
| Browser(CDP) | | |
| Browser Unblock | | |
| Browser Session Stop | | |
| 会话录制 | | |
| 反馈 | | |
Quick examples
快速示例
bash
undefinedbash
undefinedScrape 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)
scrapfly scrape https://web-scraping.dev/products
https://web-scraping.dev/product/1
https://web-scraping.dev/product/2
--format markdown --concurrency 5
https://web-scraping.dev/product/1
https://web-scraping.dev/product/2
--format markdown --concurrency 5
scrapfly scrape https://web-scraping.dev/products
https://web-scraping.dev/product/1
https://web-scraping.dev/product/2
--format markdown --concurrency 5
https://web-scraping.dev/product/1
https://web-scraping.dev/product/2
--format markdown --concurrency 5
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 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"
| 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"]}'
--url https://web-scraping.dev/products
--schema '{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"string"}},"required":["name","price"]}'
undefinedANTHROPIC_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"]}'
--url https://web-scraping.dev/products
--schema '{"type":"object","properties":{"name":{"type":"string"},"price":{"type":"string"}},"required":["name","price"]}'
undefinedReporting product feedback
报告产品反馈
scrapfly feedbackbash
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.
- a defect or blocker stopped a command from working;
--sentiment negativefriction or a workaround, but the task completed;neutralit worked, or a step behaved better than expected. File positive reports too.positive - names the command and what it did,
--messagethe goal and the CLI version. Both are 10-2000 characters, and--contextneeds five words: "it broke" is not a report anyone can act on.--message - scopes the report to a product area. An unknown value is rejected with the full list, so you can correct it from the error.
--feature - defaults to
--actorwhen a coding-agent environment variable is present,agentotherwise. Passhumanwhen you are relaying the user's own words, and keep their wording.--actor human - 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 the account's hourly budget is spent: drop the report. On any other error, show the drafted
429and--messageso the user can file it by hand.--context
scrapfly feedbackbash
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应说明目标和 CLI 版本。两者长度均为 10-2000 个字符,且--context至少需要五个单词:“it broke”并不是任何人都能据此采取行动的报告。--message - 用于将报告限定到特定产品领域。如果传入未知值,命令会拒绝执行并返回完整列表,便于你根据错误进行修正。
--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
undefinedCobra 提供适用于 bash、zsh、fish 和 PowerShell 的补全脚本。安装一次即可:
bash
undefinedzsh
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
undefinedscrapfly completion fish > ~/.config/fish/completions/scrapfly.fish
undefinedMCP server
MCP server
scrapfly mcp servescrapescreenshotextractcrawl_runselectorjsonc
{
"mcpServers": {
"scrapfly": {
"command": "scrapfly",
"args": ["mcp", "serve"],
"env": { "SCRAPFLY_API_KEY": "scp-live-..." }
}
}
}Selector discovery also works from inside the agent loop via the
tool - useful when the model wants to produce a durable
CSS selector instead of relying on per-snapshot refs.
find_selectorscrapfly mcp servescrapescreenshotextractcrawl_runselectorjsonc
{
"mcpServers": {
"scrapfly": {
"command": "scrapfly",
"args": ["mcp", "serve"],
"env": { "SCRAPFLY_API_KEY": "scp-live-..." }
}
}
}在 Agent 循环中,也可以通过 工具发现选择器。当模型希望生成稳定的 CSS selector,而不是依赖每次 snapshot 中的临时引用时,该功能非常有用。
find_selectorReference
参考
- Docs: https://scrapfly.io/docs
- SDKs: https://scrapfly.io/docs/sdk
- CLI source + examples: https://github.com/scrapfly/scrapfly-cli