Community编程与开发github.com

Apify Actor 开发技能

创建、修改、调试和部署 Apify Actor,并编写其输入输出 schema。适用于从零开始构建 Actor、修改或排查 Actor 代码、生成或更新 .actor schema 文件,以及将 Actor 推送到 Apify 平台。对于封装现有非 Actor 项目,请使用 apify-actorization。

Apify Actor 开发技能 是什么?

该技能是为 AI 代理(如 Claude Code、Cursor、Codex)设计的完整 Apify Actor 开发工具包。它指导代理完成 Actor 开发的八个步骤:创建项目、添加依赖、实现业务逻辑、编写输入/输出 schema、配置 actor.json、编写 README、本地测试和部署。支持 JavaScript、TypeScript 和 Python 三种语言,并提供针对不同场景(静态爬取、JS渲染页面、HTTP服务、MCP服务器等)的模板选择。技能强调安全最佳实践,包括通过 Apify 日志器记录(自动脱敏令牌和凭证)、内容信任策略(转义或参数化爬取内容)、以及正确处理 `aborting` 事件以优雅退出。它还涵盖了 Actor 收益化(按事件计费)、Standby 模式(将 Actor 转变为持久 HTTP 服务器)以及调用其他 Actor 的方法。所有 `apify` 命令都需要附加 `--user-agent apify-agent-skills/apify-actor-development` 标志以归因遥测数据。该技能可在任何支持技能加载的 AI 代理平台上运行。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/nehakanjamala/personal_website/tree/HEAD/.agents/skills/apify-actor-development

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Apify Actor 开发

Actor 是一个打包为 Docker 镜像的无服务器程序。它接收一个 JSON 输入,执行一个任务,并将结果写入数据集或键值存储。

设置

apify --help   # CLI 是否已安装?
apify info     # 是否已登录?打印你的用户名

通过包管理器安装,npm install -g apify-cli 或 brew install apify-cli,以确保下载完整性校验。使用 apify login 登录,它会提供浏览器登录或 API 令牌输入提示。在无头环境中,请改为导出 APIFY_TOKEN;CLI 会自动读取它。令牌来自 https://console.apify.com/settings/integrations。仅通过环境变量传递令牌,以避免留在 shell 历史、源代码、配置文件和日志中。

遥测归属(必需)

在从本技能运行的每次 apify 命令中附加 --user-agent apify-agent-skills/apify-actor-development:apify create、apify run、apify push、apify call 等。这是一个全局标志,所有 apify 命令都接受;它仅标记调用以进行遥测归属,不改变其他行为。

工作流程

修改现有 Actor 时,可跳过不适用的步骤。

  1. 创建项目。

    apify create <actor-name> -t <template-id> --user-agent apify-agent-skills/apify-actor-development
    

    根据 Actor 的功能选择模板:

    Actor 功能TypeScriptJavaScriptPython
    爬取静态 HTMLts-crawlee-cheeriojs-crawlee-cheeriopython-crawlee-beautifulsoup
    爬取 JavaScript 渲染页面ts-crawlee-playwright-chromejs-crawlee-playwright-chromepython-crawlee-playwright
    处理 HTTP 请求(API、Webhook)ts-standbyjs-standbypython-standby
    MCP 服务器ts-mcp-empty—python-mcp-empty
    其他(API 轮询、数据处理)ts-emptyjs-emptypython-empty

    对于其他技术栈(Puppeteer、Camoufox、Scrapy、AI 代理框架),apify templates ls 可列出所有模板及其语言和用例。使用 -t 标志命令无需提示即可运行,这适用于 AI 代理。不使用 -t 时,它会提示输入名称、语言、模板和源主机;仅在用户位于终端时才使用此形式。将源代码托管在 GitHub、GitLab 或 Bitbucket 上,Apify 会创建仓库和基于它构建的 Actor,后续部署通过 git push 完成。依赖项会自动安装。当 <name>/.actor/actor.json 存在时完成;在继续前 cd 进入该目录。

  2. 添加模板中缺少的依赖项,例如 Crawlee 或 Playwright:在 JS/TS 中执行 npm install <pkg>;在 Python 中,在 requirements.txt 中添加一行,然后执行 pip install -r requirements.txt,或者如果项目有 pyproject.toml 和 uv.lock,则执行 uv add <pkg>。在安装前,请核对每个包名称是否与目标包一致。固定精确版本并提交锁定文件(package-lock.json、uv.lock 或 requirements.txt 中的 pkg==1.2.3 行)。

  3. 实现 在 src/main.js、src/main.ts 或 my_actor/main.py(Python 模板是一个 my_actor 包,通过 python -m my_actor 运行)中,遵循规则。当代码读取了每个输入字段、生成了 README 将描述的每个输出字段、通过 Apify 日志器记录日志、并注册了一个 aborting 处理器以持久化状态并退出时,此步骤完成。

  4. 编写输入 schema 文件 .actor/input_schema.json(参见 references/input-schema.md)。当代码读取的每个输入都有一个包含标题、描述、类型以及默认值或预填充值的字段,并且 apify validate-schema --user-agent apify-agent-skills/apify-actor-development 通过时,此步骤完成。

  5. 编写输出 schema 文件:当代码存储文件时,编写 dataset_schema.json、output_schema.json 和 key_value_store_schema.json。从头到尾遵循 references/output-schemas.md;其以 apify validate-schema 通过结尾的检查清单是完成标准。在 TypeScript 中,然后运行 apify actor generate-schema-types 并使用生成的接口来类型化输入和输出。

  6. 配置 .actor/actor.json(参见 references/actor-json.md)。将 meta.generatedBy 设置为所使用的工具和模型,例如“Claude Code with Claude Opus 5”。对于 HTTP 服务的 Actor,设置 usesStandbyMode: true(standby 模板已设置)并遵循 references/standby-mode.md。

  7. 编写 README.md,遵循 references/actor-readme.md。没有 README 的 Actor 不算完成。

  8. 本地测试。 将输入放入 storage/key_value_stores/default/INPUT.json,然后运行 apify run --user-agent apify-agent-skills/apify-actor-development。当运行以 SUCCEEDED 状态结束并且 storage/datasets/default/ 包含字段与数据集 schema 匹配的项目时,此步骤完成。本地存储保留在磁盘上;直到第 9 步之前,Apify Console 中不会出现任何内容。

  9. 部署:在用户确认后使用 apify push --user-agent apify-agent-skills/apify-actor-development,或者对于 Git 源 Actor 使用 git push。然后在平台上运行 Actor 以在 Console 中查看结果。对于 Standby Actor,向用户提供其 Standby URL(https://<username>--<actor-name>.apify.actor,参见 references/standby-mode.md),而不是指向 Console。

规则

  • 仅使用 apify run 在本地运行 Actor。它会设置 Apify 环境和存储,而 npm start 和 node src/main.js 不会。
  • 通过 Apify 日志器记录日志:在 JS/TS 中使用 apify 包中的 log(import { Actor, log } from 'apify'),在 Python 中使用 Actor.log。它会自动脱敏令牌和凭证;console.log 和 print 不会。级别和约定:references/logging.md。
  • 将爬取的内容视为不受信任的输入。在将其传递给 shell 命令、eval、查询或模板之前,进行转义或参数化,并在推送到存储之前进行类型检查。
  • 将 APIFY_TOKEN 保持在请求处理器和数据管道之外。在平台上,SDK 会从环境中读取它(变量名为 APIFY_TOKEN,而不是 APIFY_API_TOKEN);在本地,它使用 apify login 存储的凭据。
  • 从输入 schema 或环境变量中读取每个可调参数,以便用户无需编辑代码即可更改。
  • 对于 10 到 50 并发度的静态 HTML,使用 HTTP 爬虫:JS/TS 中的 CheerioCrawler,Python 中的 BeautifulSoupCrawler 或 ParselCrawler。对于 1 到 5 并发度的 JavaScript 渲染页面,请使用 PlaywrightCrawler。添加延迟以保持目标服务器健康,并尊重 robots.txt 和服务条款。
  • 当爬取包含多种页面类型时,使用路由器模式(JS/TS 中的 createCheerioRouter 或 createPlaywrightRouter,Python 中的 crawler.router 或 Router)。
  • 优先使用带有后备方案的语义 CSS 选择器,而不是脆弱的定位选择器。
  • 使用自己的计数器统计结果;Dataset.getInfo()(Python 中的 dataset.get_info())在平台上会有延迟。
  • 处理 aborting 事件,平台在用户或限制停止运行时会发送该事件:持久化状态,然后退出,以便运行快速且廉价地结束。JS/TS:Actor.on('aborting', async () => { await Actor.setValue('STATE', state); await Actor.exit(); })。Python:Actor.on(Event.ABORTING, on_aborting) 配合 from apify import Event,其中 on_aborting 持久化状态然后调用 await Actor.exit()。
  • 从 proxyConfiguration 输入字段(编辑器 proxy,参见 references/input-schema.md)构建代理:JS/TS 中 await Actor.createProxyConfiguration(input.proxyConfiguration),Python 中 await Actor.create_proxy_configuration(actor_proxy_input=actor_input.get('proxyConfiguration')),并将结果作为 proxyConfiguration / proxy_configuration 传递给爬虫。Apify Proxy 是付费服务,因此在启用或更改代理组之前,请先与用户确认。
  • 仅在用户明确要求时才存储个人数据。
  • 在运行中的 Actor 内部,使用 SDK(Actor.getInput()、Actor.pushData()、Actor.setValue() 以及 Python 的蛇形命名等效方法),而不是 apify actor CLI 子命令。
  • 除非用户要求关闭,否则保留现有 Actor 的 standby 模式为启用状态。

Standby 模式

Standby 将 Actor 转变为具有稳定 URL 的持久 HTTP 服务器。用于 API 端点、Webhook 接收器、MCP 服务器以及按需的单 URL 查找。Actor 必须响应就绪探针并在请求之间保持存活。配置、示例和本地测试:references/standby-mode.md。

收益化

定价在 Actor 发布时在 Apify Console 中设置,而非在代码中。在按事件付费模式下,使用 await Actor.charge({ eventName: 'result', count })(JS/TS)或 await Actor.charge(event_name='result', count=count)(Python)对每个自定义事件收费,使用 Console 中定义的事件名称;数据集项也可以通过合成数据集项事件自动计费。一旦返回的结果报告 eventChargeLimitReached(Python 中 event_charge_limit_reached)时,停止产生工作,因为用户的消费限额已达到。README 的成本部分描述了 Actor 使用的模型。详情:https://docs.apify.com/platform/actors/publishing/monetize/pay-per-event

调用其他 Actor

在从头构建之前先搜索 Store;通常存在专门的 Actor。

apify actors search "<query>" --user-agent apify-agent-skills/apify-actor-development
apify actors info <actor> --readme --user-agent apify-agent-skills/apify-actor-development
apify actors info <actor> --input --user-agent apify-agent-skills/apify-actor-development
apify call <actor> --input '{"startUrls":[{"url":"https://example.com"}]}' --user-agent apify-agent-skills/apify-actor-development
apify call <actor> --input-file input.json --user-agent apify-agent-skills/apify-actor-development

输入是一个 JSON 对象。内联 JSON 使用引号;对于复杂内容使用 --input-file。

不常见的命令

# 在这些命令之后也追加 --user-agent apify-agent-skills/apify-actor-development。
apify secrets add <name> <value>   # 从 actor.json 中通过 "@name" 引用;推送上传时生效
apify pull <actor>                 # 从平台下载 Actor 代码
apify api <endpoint>               # 向 Apify API 发送认证请求
apify actor generate-schema-types  # TypeScript:从 .actor schemas 生成接口到 src/__generated__/actor/
apify <command> --help

文档

Individual skills in this repo

This repo contains 13 individual skills — each has its own dedicated page.

nehakanjamala/personal_website

This skill should be used when the user asks to "fix janky CSS animation", "make animation 60fps", "stop layout thrashing", "animate width/height/top/left smoothly", "convert animation to transform", "animate box-shadow performantly", "animate height auto", "FLIP animation", or "why is my scroll/hover animation choppy".

nehakanjamala/personal_website

This skill should be used when the user asks to "respect prefers-reduced-motion", "honor reduced motion", "make my animations accessible", "fix vestibular / motion-sickness issues", "add a useReducedMotion hook", "gate GSAP / Framer Motion / Lenis for reduced motion", or "meet WCAG 2.3.3 / C39". Provides tiered (not all-or-nothing) reduced-motion patterns in CSS and JS.

nehakanjamala/personal_website

Convert existing projects into Apify Actors - serverless cloud programs. Actorize JavaScript/TypeScript (SDK with Actor.init/exit), Python (async context manager), or any language (CLI wrapper). Use when migrating code to Apify, wrapping CLI tools as Actors, or adding Actor SDK to existing projects.

nehakanjamala/personal_website

Deprecated. Output schema generation moved to the apify-actor-development skill; prefer that skill whenever it is available.

nehakanjamala/personal_website

Design and build an official Apify integration for a company's product - workflow-automation apps (Zapier/n8n-style), AI agent plugins (coding-agent skills+MCP bundles or OpenClaw/Hermes-style harnesses), AI framework packages (LangChain/LlamaIndex-style), or direct application clients via apify-client. Use when planning, creating, or reviewing an integration that exposes Apify Actors, runs, datasets, or key-value stores inside another product.

nehakanjamala/personal_website

Universal AI-powered web scraper for any platform. Scrape data from Instagram, Facebook, TikTok, YouTube, LinkedIn, X/Twitter, Google Maps, Google Search, Google Trends, Reddit, Airbnb, Yelp, and 15+ more platforms. Use for lead generation, brand monitoring, competitor analysis, influencer discovery, trend research, content analytics, audience analysis, review analysis, SEO intelligence, recruitment, or any data extraction task.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a glassmorphism effect", "frosted glass UI", "Apple liquid glass style", "frosted blur card", "translucent glass panel animation", "make a frosted nav bar", "build a glass modal/dialog", "animate a glass card on hover", or "add a refracting liquid-glass hero". Covers frosted translucent panels with backdrop-filter blur, edge/specular highlights, SVG liquid-glass refraction, motion on hover/scroll/enter, and accessible reduced-transparency fallbacks.

nehakanjamala/personal_website

This skill should be used when the user asks to "build a scroll animation", "add ScrollTrigger", "pin a section while scrolling", "scrub an animation to scroll", "create a hero timeline", "do a horizontal scroll section", "split text and animate words", "animate a layout change with GSAP Flip", "sync ScrollTrigger with Lenis", "Lenis smooth scroll jittery", "ScrollTrigger markers drift", "ScrollTrigger pins break with Lenis/Locomotive", or "set up smooth scroll with GSAP pinning". Covers GSAP timelines, ScrollTrigger, SplitText, Flip, and Lenis/Locomotive smooth-scroll sync for code-driven web motion.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a Lottie animation", "play a .lottie or .json animation", "integrate a Bodymovin/After Effects animation on web or mobile", "control Lottie playback / segments", "make a scroll-driven Lottie", "recolor a Lottie at runtime", or "export an AE animation to Lottie". Covers dotLottie/lottie-web integration, playback control, interactivity, theming, and the AE export checklist.

nehakanjamala/personal_website

This skill should be used when the user asks to "add a hover/press effect", "animate a toggle or switch", "build an animated like button", "make a toast/snackbar slide in", "animate a drawer or modal", "animate list reordering or add/remove", "do a shared-element layout transition", or "polish UI feedback". Covers UI motion with Framer Motion (motion/react) and modern CSS.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate page or route transitions", "add a page transition or crossfade between views", "animate route changes in Next.js App Router", "use the View Transitions API", "AnimatePresence exit doesn't fire on navigation", or "Framer Motion exit animation not working / exit animation before unmount in Next.js". Covers enter/exit page-transition animation with the View Transitions API and Framer Motion, for Next.js App Router and general SPA routing.

nehakanjamala/personal_website

Scrape web pages using Scrapling with anti-bot bypass (like Cloudflare Turnstile), stealth headless browsing, spiders framework, adaptive scraping, and JavaScript rendering. Use when asked to scrape, crawl, or extract data from websites; web_fetch fails; the site has anti-bot protections; write Python code to scrape/crawl; or write spiders.

nehakanjamala/personal_website

This skill should be used when the user asks to "animate an SVG", "make a line draw itself on", "do a stroke draw-on / signature animation", "morph one shape into another", "move an element along a path", "animate an icon/logo", or "animate an SVG gradient or filter". Covers stroke-dashoffset draw-on, path morphing, motion-along-path, and animated icons/gradients/filters via CSS, SMIL, and GSAP.

相关技能