跳转到内容

Worker 输入配置 (Input Schema)

这份文档旨在指导开发者如何配置 input_schema.json 文件。这个文件决定了自动化 Worker 在网页界面上呈现给用户的输入表单样式


脚本输入配置 (Input Schema) 使用手册

Section titled “脚本输入配置 (Input Schema) 使用手册”

input_schema.json 是脚本的”面孔”。通过修改此文件,您可以控制用户在启动脚本前需要填写哪些参数(如 URL、关键词、日期等),以及这些输入框是以什么形式展示的(下拉框、勾选框、文本框等)。

一个标准的配置文件通常包含以下根字段:

  1. description (描述):向用户介绍这个脚本的功能和用法。
  2. concurrency (并发配置):决定平台如何把一次 Worker 运行拆分成多个 task。
  3. properties (参数列表):具体的功能设置项。
{
"description": "With our Instagram Reel information scraper tool, after a successful scrape, you can extract the Reel author's username, Reel caption, hashtags used in the post, number of comments on the Reel, Reel publish date, likes count, views count, play count, popular comments, unique post identifier, URL of the Reel's display image or video thumbnail, product type, Reel duration, video URL, post audio link, number of posts on the profile, number of followers on the profile, profile URL, whether the account is a paid partner, and other relevant information.",
"concurrency": {
"fields": ["startUrl"]
},
"properties": [
{
"title": "URL",
"name": "startUrl",
"type": "array",
"editor": "requestList",
"description": "This parameter is used to specify the Instagram access URL to be fetched.",
"default": [
{
"url": "https://www.instagram.com/reel/C5Rdyj_q7YN/"
}
],
"required": true
}
]
}
字段名称是否必填功能说明
description工具简介。会显示在页面顶端,支持填写脚本的作用、注意事项等,字数不限。
concurrency任务拆分配置。用于拆分 task,包含 fields 和可选的 remove_fields
properties参数配置数组。这里存放所有的输入项,每一个元素代表页面上的一个输入框或选择器。

提交运行任务时,CoreClaw 会按以下顺序判断如何拆分 task:

  1. 如果 concurrency.fields 中至少有一个非空字段名,平台使用并发规则。
  2. 如果 concurrency.fields 为空或不存在,整份提交的输入会作为一个 task 运行。
字段类型说明
fieldsstring[]候选并发字段列表。每个字段都应匹配一个 properties[*].name,且对应 property 的 type 应为 array
remove_fieldsstring[]可选。用于在优先字段有值时,从 task 输入中剔除某些字段。每个值也应属于 fields

平台会先计算:

preferred = fields - remove_fields

然后选择真正参与拆分的 active fields:

  • 如果 preferred 中任意字段在提交输入里有非空值,则只使用 preferred 参与拆分。
  • 否则使用完整的 fields,包括写在 remove_fields 里的字段。

拆分 task 前,平台会过滤空的并发元素。以下值会被视为空:

  • null
  • 空字符串或纯空白字符串,例如 """ "
  • 空对象,例如 {}
  • 所有字段值都为空的对象,例如 { "place_id": "" }{ "foo": null, "bar": "" }

如果某个并发数组过滤后为空,这个字段就会被视为“无值”。

每个生成出来的 task 遵循以下规则:

  • 当前被拆分的字段会保留,并且只包含当前这一项。
  • 其他 active 并发字段会保留为 [""]
  • remove_fields 禁用的字段会从 task 输入中整个删除。
  • 非并发字段会复制到每一个 task。

带关键词回退的示例:

{
"concurrency": {
"fields": ["keywords", "google_maps_urls", "place_ids"],
"remove_fields": ["keywords"]
},
"properties": [
{
"title": "Keywords",
"name": "keywords",
"type": "array",
"editor": "stringList",
"description": "Search keywords",
"required": false
},
{
"title": "Google Maps URLs",
"name": "google_maps_urls",
"type": "array",
"editor": "requestList",
"description": "Google Maps URLs",
"required": false
},
{
"title": "Place IDs",
"name": "place_ids",
"type": "array",
"editor": "stringList",
"description": "Google Maps place IDs",
"required": false
}
]
}

如果用户提交:

{
"keywords": ["pizza", "iphone"],
"google_maps_urls": ["urlA", "urlB"],
"place_ids": [],
"base_location": "New York, USA"
}

平台会生成两个 task:

{
"google_maps_urls": ["urlA"],
"place_ids": [""],
"base_location": "New York, USA"
}
{
"google_maps_urls": ["urlB"],
"place_ids": [""],
"base_location": "New York, USA"
}

因为 google_maps_urls 有值,并且 keywordsremove_fields 中,所以 keywords 会被整个删除。

如果 google_maps_urlsplace_ids 都为空,平台会回落到 keywords 拆分,并把另外两个并发字段保留为 [""]

场景结果
不写 remove_fieldsfields 中所有非空字段都会参与拆分。task 数量等于这些字段有效元素数量之和。
fields 只有一个字段运行会按这一个数组字段拆分。
remove_fields 字段被禁用该 key 会从 task 输入中整个删除,不会保留为 [""]
preferred 字段只有 ""null{} 或全空对象视为空,不会触发 remove_fields
URL 中包含 &平台会按提交值保留 URL。Worker 代码里避免再次用会 HTML 转义 & 的方式序列化。
并发数组里包含超大整数平台 JSON 解析阶段会保留数值,但如果还要跨语言或跨服务读取,仍建议传字符串。
生成 task 数超过限制平台会先计数再拒绝运行,不会先展开全部 task payload。业务侧仍应避免提交超大数组。

custom[fieldName] 数组中的每个元素都遵循同一套规则:

元素类型示例是否支持处理方式
对象{ "url": "https://a.com" }支持合并进 task 输入,不再保留在并发字段名下面;子字段覆盖父级字段。
字符串"pizza"支持包装成 ["pizza"]。纯空白字符串会被过滤为空。
数字42, 3.14支持包装成 [42][3.14]。平台解析器会保留超大整数,但跨语言传输时仍建议用字符串。
布尔值true支持包装成 [true]
nullnull视为空拆分前过滤。
嵌套数组["first", "second"] 当作一个元素不支持会触发运行时报错。
对象和原始值混用[{ "url": "a" }, "x"]不支持会触发运行时报错。同一个字段内应保持元素类型一致。
报错信息触发原因修复建议
input_schema is not a valid jsonschema 文件不是合法 JSON。上传前先校验 JSON。
custom parameters must contain a single JSON object提交输入不是单个顶层 object。提交单个 JSON object。
concurrency fields must have at least one fieldconcurrency.fields 没有有效字段名。至少添加一个字段名。
concurrency fields have no non-empty fields所有并发字段过滤后都为空。至少提交一个非空值。
field [X] must be an array并发字段存在,但值不是数组。改成数组值。
item at index N in [X] must be an object or primitive value并发数组元素是嵌套数组或不支持的类型。使用对象或原始值元素。
field [X] must not mix object and primitive items同一个数组里混用了对象和原始值。统一元素类型。
concurrency_num (N) exceeds limit (M)生成的 task 数超过平台限制。减少输入数量或调整平台限制。
  • 使用 concurrency.fields 配置任务拆分。
  • 每个并发字段都应匹配一个 properties[*].name,且对应 type: "array"
  • 如果使用 remove_fields,它应是 fields 的子集。
  • 不要假设 remove_fields 中的字段一定存在于 task 输入里;它可能会被整个删除。
  • 同一个并发数组里不要混用对象元素和原始值元素。
  • 不要使用嵌套数组作为并发元素。

四、参数项属性详解 (Properties 内部)

Section titled “四、参数项属性详解 (Properties 内部)”

每一个具体的输入项都必须是对象。普通 Worker schema 中,每个 property 建议包含以下字段:

字段类型是否必填说明
titlestring表单展示名称。
namestringWorker 代码读取的内部字段名。必须唯一,建议匹配 ^[A-Za-z_][A-Za-z0-9_]*$
typestring数据类型,见下方 type 表。
editorstring前端表单控件,见下方 editor 表。
descriptionstring输入框下方的补充说明。
requiredboolean设为 true 时,用户不填无法启动 Worker。
defaulttype 一致表单初始值,类型应与 type 匹配。
optionsarraycheckboxselectradio 的可选项。
Type含义常见 default常用 editor
string字符串"abc"inputtextareaselect
integer整数42numberinput
number浮点数3.14number
boolean布尔值true / falseswitch
array数组[] / [...]checkboxstringListrequestList
object对象{}较少直接使用
Editor推荐 type用途
inputstringintegernumber单行文本或简单数字输入
textareastring多行文本
numberintegernumber数字输入
switchboolean开关设置
checkboxarray多选
selectstringinteger单选下拉
radiostringinteger单选按钮
stringListarray字符串列表
requestListarrayURL 或请求对象列表

五、编辑器类型 (Editor) 选型指南

Section titled “五、编辑器类型 (Editor) 选型指南”

您可以根据需要选择不同的 editor 来优化用户体验:

类型值呈现形式适用场景
input单行文本框简短文字、关键词、账号名。
textarea多行大文本框备注、长段文字说明。
number数字调节框限制采集数量、页码、等待秒数。
类型值呈现形式示例
select下拉菜单选性别、选语言、选地区。
radio单选框二选一、三选一的排列按钮。
checkbox多选框勾选多个感兴趣的标签。
switch开关是否开启
类型值呈现形式适用场景
datepicker日期选择器筛选特定发布日期。
requestListURL 地址列表批量输入需要采集的网页链接(支持 Excel 导入样式)。
requestListSourceURL请求列表源可自定义配置其他参数。
stringList字符串列表批量输入多个关键词。

{
"title": "Location (use only one location per run)",
"name": "location",
"type": "string",
"editor": "input",
"default": "New York, USA"
}
{
"title": "Filter reviews by keywords",
"name": "keywords",
"type": "string",
"editor": "textarea"
}
{
"title": "Number of places to extract (per each search term or URL)",
"name": "maxPlacesPerSearch",
"type": "integer",
"editor": "number",
"default": 4
}

设置 multiple: true 后,用户可以选择多个选项。

{
"title": "Language",
"name": "language",
"type": "string",
"editor": "select",
"options": [
{
"label": "English",
"value": "en"
},
{
"label": "Chinese",
"value": "zh"
}
],
"default": "en"
}
{
"title": "Category",
"name": "radio",
"type": "integer",
"editor": "radio",
"options": [
{
"label": "hotel",
"value": 1
},
{
"label": "restaurant",
"value": 2
}
],
"default": 1
}
{
"title": "Data Sections to Scrape",
"name": "data_sections",
"type": "array",
"editor": "checkbox",
"options": [
{
"label": "Reviews",
"value": "reviews"
},
{
"label": "Address",
"value": "address"
},
{
"label": "Phone Number",
"value": "phone_number"
}
],
"default": ["reviews", "address"]
}
{
"title": "Extract posts that are newer than",
"name": "date",
"type": "string",
"editor": "datepicker",
"format": "DD/MM/YYYY",
"valueFormat": "DD/MM/YYYY"
}
{
"title": "Skip closed places",
"name": "skipClosed",
"type": "boolean",
"editor": "switch"
}

对象数组,支持自定义键名:

{
"name": "startURLs",
"type": "array",
"title": "Start URLs",
"editor": "requestList",
"default": [
{
"key": "value1"
},
{
"key": "value2"
}
],
"required": true,
"description": "The URLs of the website to scrape"
}

或纯字符串数组:

{
"name": "startURLs",
"type": "array",
"title": "Start URLs",
"editor": "requestList",
"default": [
"value1",
"value2"
],
"required": true,
"description": "The URLs of the website to scrape"
}

10. URL 请求列表源 (requestListSource)

Section titled “10. URL 请求列表源 (requestListSource)”

requestList 类似,但允许通过 param_list 为每个 URL 条目定义额外的自定义参数。

{
"name": "url",
"type": "array",
"title": "startURLs",
"editor": "requestListSource",
"default": [
{
"url": "https://www.instagram.com/espn",
"num_of_posts": "10"
}
],
"param_list": [
{
"param": "url",
"title": "URL",
"required": true,
"description": "要采集的 URL 地址"
},
{
"param": "num_of_posts",
"title": "最大帖子数",
"description": "最多获取的帖子数量"
}
],
"description": "要采集的网站 URL"
}

对象数组,支持自定义键名:

{
"title": "Search term(s)",
"name": "searchTerms",
"type": "array",
"editor": "stringList",
"default": [
{
"key": "value1"
},
{
"key": "value2"
}
]
}

或纯字符串数组:

{
"title": "Search term(s)",
"name": "searchTerms",
"type": "array",
"editor": "stringList",
"default": [
"value1",
"value2"
]
}

允许开发者通过特定的字段标,将多个配置项进行逻辑归类。当配置项数量较多时,通过分组可以有效提升界面的可读性与可维护性,帮助用户更清晰地定位和理解配置内容。

参数示例值参数类型是否必填参数描述
sectionCaption-String用于定义个分组的显示标题。当配置项中包含此属性时,视为新分组的开始。
sectionDescription-String用于对当前分组进行补充说明,提供更详细的上下文信息。
{
"description": "Find usernames across 400+ social networks. Check if a username is available or already taken on various platforms.",
"concurrency": {
"fields": ["username"]
},
"properties": [
{
"title": "Username",
"name": "username",
"type": "array",
"editor": "stringList",
"description": "Username(s) to search. One per line.",
"default": [
"john_doe"
],
"required": true
},
{
"title": "Timeout (secs)",
"name": "timeout",
"type": "integer",
"editor": "number",
"description": "Request timeout in seconds per site.",
"default": 30,
"sectionCaption": "Request control and result settings",
"sectionDescription": "Configure the performance parameters of the crawler requests."
}
]
}
  1. 清晰的提示:description 务必清晰准确,这将有利于您的脚本被更多目标用户检索到。
  2. 设置默认值:合理的 default 可以让用户直接点击运行,极大地降低使用门槛。
  3. 校验必填:对于没有它脚本就无法运行的参数(如登录 Cookie、主链接),一定要设置 "required": true
  4. 明确配置任务拆分:需要按数组输入拆分 task 时,使用 concurrency.fields。只有当一种输入模式需要禁用另一种输入模式时,才使用 remove_fields
  5. 最大结果数命名:如果 Worker 需要限制最大返回条数,字段名应使用 max_results。这是平台及下游集成所识别的标准命名。