scrape_with_actions
执行包括点击、滚动、输入和表单自动填充在内的浏览器操作链,并支持截图捕获。非常适合登录流程、无限滚动、模态对话框以及复杂的重 JavaScript 网站。
使用场景
登录流程
自动化登录表单,访问登录墙后的已认证内容
无限滚动
从社交媒体动态流和产品列表等无限滚动页面抓取内容
模态对话框
与弹窗、模态框和动态浮层进行交互
重 JavaScript 网站
处理 SPA 以及通过 AJAX 动态加载内容的网站
多步骤表单
在多步骤向导和复杂表单提交中进行导航
可视化测试
在每一步捕获截图,用于调试和视觉回归测试
Endpoint
/api/v1/tools/scrape_with_actionsParameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Required | - | 在运行操作链之前要加载的 URL Example: https://app.example.com/dashboard |
actions | array | Required | - | 在抓取之前要运行的 1-20 个浏览器操作的有序列表。每个元素都是一个对象,其 `type` 为 `wait`、`click`、`type`、`press`、`scroll`、`screenshot`、`executeJavaScript`、`select`、`hover` 或 `navigate`,外加与类型相关的字段:`selector`(CSS 目标)、`text`(用于 `type`)、`key`(用于 `press`)、`script`(用于 `executeJavaScript`)、`duration`/`condition`(用于 `wait`)、`button`/`clickCount`/`delay`(用于 `click`)、`direction`/`distance`/`toElement`(用于 `scroll`)、`fullPage`/`quality`/`format`(用于 `screenshot`)、`value` 或 `values`(用于 `select`)以及 `url`/`waitUntil`(用于 `navigate`)。`select` 接受单个 `value` 或 `values` 数组,普通字符串会按选项的 value 或可见文本进行匹配;`hover` 需要 `selector`,并可选 `force` 和 `position`。任何操作均可选:`timeout`(每个操作,默认 10000ms,区别于按整条链计算预算的 `browserOptions.timeout`)、`description`、`continueOnError`(默认 false)、`retries`(0-5,默认 1)和 `captureAfter`(默认 false)。 Example: [{"type": "click", "selector": "#login"}, {"type": "type", "selector": "#email", "text": "user@example.com"}, {"type": "wait", "duration": 1000}, {"type": "screenshot"}] |
formats | array | Optional | ["json"] | 要返回的输出格式:`markdown`、`html`、`json`、`text` 或 `screenshots` Example: ["markdown", "screenshots"] |
captureScreenshots | boolean | Optional | true | 在执行操作期间捕获截图 Example: true |
formAutoFill | object | Optional | - | 一步填写并提交表单。结构:`{ fields: [{ selector, value, type: text|select|checkbox|radio|file, waitAfter }], submitSelector, waitAfterSubmit }`——`waitAfterSubmit` 默认为 2000ms。 Example: {"fields": [{"selector": "#email", "value": "user@example.com", "type": "text"}], "submitSelector": "#login"} |
browserOptions | object | Optional | - | 浏览器配置:`headless`(默认 true)、`userAgent`、`viewportWidth`(默认 1280,范围 800-1920)、`viewportHeight`(默认 720,范围 600-1080)、`timeout`(默认 30000ms,范围 10000-120000)以及 `stealth`(默认 false)。请将 `timeout` 保持在约 25 秒的 REST 窗口内。将 `stealth` 设为 true,可用隐身 Chromium 引擎的 `medium` 配置运行整条操作链,而不使用标准浏览器池——该布尔值是唯一的开关,级别、指纹随机化和引擎选择都无法在此设置。它启动更慢,并且只是渲染 JavaScript,并不解决挑战。 Example: {"viewportWidth": 1440, "viewportHeight": 900, "timeout": 20000} |
extractionOptions | object | Optional | - | 内容提取选项:`selectors`(要提取数据的 CSS 键→值映射)、`includeMetadata`(默认 true)、`includeLinks`(默认 true)和 `includeImages`(默认 true)。 Example: {"selectors": {"title": "h1", "price": ".price"}} |
continueOnActionError | boolean | Optional | false | 当某个操作失败时继续执行其余操作,而不是中止整个操作链 Example: false |
maxRetries | number | Optional | 1 | 失败时整体运行的最大重试次数(0-3) Example: 1 |
respect_robots | boolean | Optional | true | 遵守目标站点的 robots.txt。省略该参数时按合规默认值(`true`)执行:robots.txt 对 `CrawlForge` 禁止的 URL 会在打开浏览器之前被拒绝,此端点不会为此扣费,每个 `navigate` 操作也会同样检查。仅在您与目标站点另有约定时才设为 `false`——该覆盖会记录到您的 API key 上。 Example: true |
可用的操作类型
{"type": "wait", "duration": 2000}{"type": "click", "selector": "#button"}{"type": "type", "selector": "#search", "text": "query"}{"type": "press", "key": "Enter"}{"type": "scroll", "toElement": "#content"}{"type": "screenshot"}{"type": "executeJavaScript", "script": "window.scrollTo(0, 0)"}<select> 中选择选项:selector 指定下拉框,然后使用 value(单个选项)或 values(多个选项)。普通字符串会按选项的 value 或可见文本进行匹配。selector 指定的元素上——适用于仅在悬停时出现的菜单和提示。force 与 position 的行为与 click 相同。url,因此先前操作留下的 cookie、localStorage 和登录状态都会保留。可选的 waitUntil 取值为 load、domcontentloaded(默认)、networkidle 或 commit。新 URL 会经过与初始 URL 相同的 robots.txt 和 SSRF 检查,因此无法借此绕过限制。请求示例
curl -X POST https://crawlforge.dev/api/v1/tools/scrape_with_actions \
-H "X-API-Key: cf_test_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://app.example.com/dashboard",
"actions": [
{"type": "click", "selector": "#login"},
{"type": "type", "selector": "#email", "text": "user@example.com"},
{"type": "type", "selector": "#password", "text": "secret123"},
{"type": "wait", "duration": 1000},
{"type": "screenshot"}
],
"formats": ["markdown", "screenshots"]
}'响应示例
{ "success": true, "data": { "url": "https://app.example.com/dashboard", "actionsExecuted": 4, "results": { "markdown": "# Dashboard\n\nWelcome back — you are now signed in...", "screenshots": [ "data:image/png;base64,iVBORw0KGgoAAAANS...(truncated)" ] }, "actionLog": [ { "type": "click", "selector": "#login", "success": true }, { "type": "type", "selector": "#email", "success": true }, { "type": "wait", "duration": 1000, "success": true }, { "type": "screenshot", "success": true } ] }, "credits_used": 5, "credits_remaining": 995, "processing_time": 9000}data.url在运行操作链之前所加载的 URLdata.actionsExecuted成功执行的操作数量data.results.markdown所有操作完成后,以每种请求格式返回的页面内容data.results.screenshots运行期间捕获的 base64 编码截图(data:image/png;base64,…)data.actionLog每个操作的日志,包含类型、选择器和成功状态credits_used本次请求扣除的 credits(每次抓取 5 个)processing_time总耗时(毫秒),包含所有操作和等待错误处理
浏览器运行时未配置(503 TOOL_NOT_AVAILABLE)
该工具需要浏览器自动化运行时。当托管执行后端未配置时,调用会立即返回 503,且不扣除 credits。
执行后端超时(504 MCP_UPSTREAM_TIMEOUT)
导航加上动作链超出了执行后端的时间预算。请缩短等待、减少动作数量,或稍后重试。失败不计费。
被 robots.txt 阻止(502 TOOL_ERROR)
目标站点的 robots.txt 对 CrawlForge 禁止了该 URL,因此没有启动任何浏览器,也没有产生任何费用。每个 navigate 操作都会同样检查,而不仅是初始 URL。若您与目标站点另有约定,可设置 respect_robots: false 予以覆盖——该覆盖会记录到您的 API key 上。
无效操作(400 Bad Request)
一个或多个操作的参数无效。请检查操作类型和必填字段。
Credits 不足(402 Payment Required)
您的账户 credits 不足(需要 5 个)。购买更多 credits 或 升级您的套餐。
超出速率限制(429 Too Many Requests)
您已超出套餐的速率限制。请稍候片刻,或 升级您的套餐 以获得更高限额。
Credit 费用
Free 套餐: 1,000 个一次性试用 credits = 200 条操作链
Hobby 套餐: 5,000 credits/月 = 1,000 条操作链($19/mo)
Professional 套餐: 50,000 credits/月 = 10,000 条操作链($99/mo)
Business 套餐: 250,000 credits/月 = 50,000 条操作链($399/mo)