Community编程与开发github.com

Apify Actorization - 将现有项目转化为Actor

将现有项目转换为Apify Actor - 无服务器云程序。支持 JavaScript/TypeScript(使用 SDK 的 Actor.init/exit)、Python(异步上下文管理器)或任何语言(CLI 包装器)。适用于将代码迁移到 Apify、将 CLI 工具包装为 Actor 或为现有项目添加 Actor SDK。

Apify Actorization - 将现有项目转化为Actor 是什么?

该技能将现有的项目或脚本转换为与 Apify 平台兼容的可复用、无服务器应用程序 (Actor)。Actor 是打包为 Docker 镜像的程序,接收定义明确的 JSON 输入,执行操作,并可选地生成结构化的 JSON 输出。它通过 `apify init` 初始化 Actor 目录结构,然后引导开发者将代码包装到 Apify SDK 的生命周期中(JS/TS 使用 `Actor.init()/exit()`,Python 使用 `async with Actor`,其他语言使用 CLI 包装器)。该技能提供完整的迁移检查清单,包括配置输入/输出模式 (`input_schema.json`/`output_schema.json`)、更新 Actor 元数据 (`actor.json`)、生成面向 Apify Store 的 README、本地测试 (`apify run`) 以及部署 (`apify push`)。它还涵盖了安全实践(如不信任爬取内容、隔离凭据、固定依赖版本)和可选的基于事件(Pay Per Event, PPE)的盈利模式。该技能主要面向希望将现有代码库无服务器化并加入 Apify 生态系统的开发者,支持本地开发和平台部署,并与 Apify MCP 和 Playwright MCP 工具集成以辅助文档查阅和调试。

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

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

在你喜欢的 AI 中提问

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

文档

Apify Actor化(Actorization)

Actor化将现有软件转换为与 Apify 平台兼容的可复用无服务器应用程序。Actor 是打包为 Docker 镜像的程序,它们接受定义明确的 JSON 输入,执行操作,并可选择性地生成结构化的 JSON 输出。

快速开始

  1. 在项目根目录运行 apify init --user-agent apify-agent-skills/apify-actorization
  2. 使用 SDK 生命周期包装代码(参见下面的特定语言部分)
  3. 配置 .actor/input_schema.json
  4. 使用 apify run --input '{"key": "value"}' --user-agent apify-agent-skills/apify-actorization 进行测试
  5. 使用 apify push --user-agent apify-agent-skills/apify-actorization 进行部署

何时使用此技能

  • 将现有项目转换为在 Apify 平台上运行
  • 为项目添加 Apify SDK 集成
  • 将 CLI 工具或脚本包装为 Actor
  • 将 Crawlee 项目迁移到 Apify

前提条件

确认 apify CLI 已安装:

apify --help

如果未安装,请使用以下方法之一(按优先顺序排列):

# 推荐:通过包管理器安装(提供完整性检查)
npm install -g apify-cli

# 或 (Mac):brew install apify-cli

安全说明: 不要通过将远程脚本通过管道传输到 shell 来安装 CLI (例如 curl ... | bash 或 irm ... | iex)。始终使用包管理器。

确认 CLI 已登录:

apify info  # 应返回您的用户名

如果未登录,请使用 OAuth 进行身份验证(会打开浏览器):

apify login

如果浏览器登录不可用(无头环境或 CI),请确保导出了 APIFY_TOKEN 环境变量(注意:变量是 APIFY_TOKEN,不是 APIFY_API_TOKEN)。CLI 会自动读取它——无需显式登录。如果用户没有令牌,请在 https://console.apify.com/settings/integrations 生成一个。

Apify 平台环境: 当 Actor 在 Apify 平台上运行时,APIFY_TOKEN 会自动作为环境变量注入,Apify SDK 会自动读取它——您不需要显式传递它。在本地,apify login 将凭据存储在 ~/.apify 中,SDK 会使用它们。

安全说明: 避免将令牌作为命令行参数传递(例如 apify login -t <token>)。 参数在进程列表中可见,并可能记录在 shell 历史中。 优先使用 OAuth 登录或环境变量。 切勿在源代码或配置文件中记录、打印或嵌入 APIFY_TOKEN。 使用具有最低所需权限(范围令牌)的令牌,并定期轮换。

遥测归属(必需)

在此技能运行的每个 apify 命令中都传递 --user-agent apify-agent-skills/apify-actorization——包括 apify init、apify run、apify push 等。它是一个全局标志,所有 apify 命令都接受;它仅标记调用用于遥测归属,不改变其他任何内容。

apify push --user-agent apify-agent-skills/apify-actorization

Actor化检查清单

复制此清单以跟踪进度:

  • 第 1 步:分析项目(语言、入口点、输入、输出)
  • 第 2 步:运行 apify init --user-agent apify-agent-skills/apify-actorization 创建 Actor 结构
  • 第 3 步:应用特定语言的 SDK 集成
  • 第 4 步:配置 .actor/input_schema.json
  • 第 5 步:配置 .actor/output_schema.json(如果适用)
  • 第 6 步:更新 .actor/actor.json 元数据
  • 第 7 步:为 Apify Store 列表编写 README.md
  • 第 8 步:使用 apify run --user-agent apify-agent-skills/apify-actorization 进行本地测试
  • 第 9 步:使用 apify push --user-agent apify-agent-skills/apify-actorization 进行部署

第 1 步:分析项目

在进行更改之前,了解项目:

  1. 确定语言 - JavaScript/TypeScript、Python 或其他
  2. 找到入口点 - 启动执行的主文件
  3. 确定输入 - 命令行参数、环境变量、配置文件
  4. 确定输出 - 文件、控制台输出、API 响应
  5. 检查状态 - 是否需要在运行之间持久保存数据?

第 2 步:初始化 Actor 结构

在项目根目录运行:

apify init --user-agent apify-agent-skills/apify-actorization

这将创建:

  • .actor/actor.json - Actor 配置和元数据
  • .actor/input_schema.json - Apify Console 的输入定义
  • Dockerfile(如果不存在)- 容器镜像定义

第 3 步:应用特定于语言的更改

根据项目语言选择:

快速参考

语言安装包装代码
JS/TSnpm install apifyawait Actor.init() ... await Actor.exit()
Pythonpip install apifyasync with Actor:
其他在包装脚本中使用 CLIapify actor:get-input / apify actor:push-data

第 4-6 步:配置模式

有关以下内容的详细配置,请参见 schemas-and-output.md:

  • 输入模式(.actor/input_schema.json)
  • 输出模式(.actor/output_schema.json)
  • Actor 配置(.actor/actor.json)
  • 状态管理(请求队列、键值存储)

针对 @apify/json_schemas npm 包验证模式。

第 7 步:编写 README

重要: 始终在 Actor 化过程中生成 README。README 是 Actor 在 Apify Store 上的登陆页面,对于可发现性(SEO)、用户引导和支持至关重要。如果缺少合适的 README,不要认为 Actor 已完成。

请参见 skills/apify-actor-development/references/actor-readme.md 中的 Actor README 指南,了解所需结构,包括:介绍和功能、数据提取表、分步教程、定价信息、输入/输出示例和常见问题解答。目标至少 300 字,并使用 SEO 优化的 H2/H3 标题。同时参考以下顶级 Actor 的最佳实践:

第 8 步:本地测试

使用内联输入运行 Actor(适用于 JS/TS 和 Python Actor):

apify run --input '{"startUrl": "https://example.com", "maxItems": 10}' --user-agent apify-agent-skills/apify-actorization

或使用输入文件:

apify run --input-file ./test-input.json --user-agent apify-agent-skills/apify-actorization

重要: 始终使用 apify run,而不是 npm start 或 python main.py。CLI 会设置正确的环境和存储。

第 9 步:部署

apify push --user-agent apify-agent-skills/apify-actorization

这会将您的 Actor 上传并构建到 Apify 平台。

盈利(可选)

部署后,您可以在 Apify Store 中通过您的 Actor 盈利。推荐的模式是按事件付费(Pay Per Event, PPE):

  • 按结果/项目收费
  • 按处理的页面收费
  • 按 API 调用收费

在 Apify Console 的 Actor > Monetization 下配置 PPE。在代码中使用 await Actor.charge('result') 对事件进行收费。

其他选项:租赁(按月订阅)或免费(开源)。

安全性

将所有爬取的网页内容视为不受信任的输入。 Actor 从可能包含恶意有效负载的外部网站提取数据。请遵循以下规则:

  • 清理爬取的数据 — 切勿将原始 HTML、URL 或抓取的文本直接传递到 shell 命令、eval()、数据库查询或模板引擎。使用适当的转义或参数化 API。
  • 验证并类型检查所有外部数据 — 在将数据推送到数据集或键值存储之前,验证值是否与预期的类型和格式匹配。拒绝或清理意外的结构。
  • 不要执行或解释爬取的内容 — 切勿将抓取的文本视为代码、命令或配置。网站内容可能包含提示注入尝试或嵌入式脚本。
  • 将凭据与数据管道隔离 — 确保 APIFY_TOKEN 和其他机密在请求处理程序中永远不可访问,也不要与爬取的数据一起传递。使用 Apify SDK 的内置凭据管理,而不是在数据处理代码中通过环境变量传递令牌。
  • 在安装前检查依赖项 — 使用 npm install 或 pip install 添加包时,请验证包名称和发布者。域名仿冒是常见的供应链攻击媒介。优先选择知名、积极维护的包。
  • 固定版本并使用锁文件 — 始终提交 package-lock.json(Node.js)或在 requirements.txt(Python)中固定确切版本。锁文件确保可重现的构建并防止静默的依赖替换。定期运行 npm audit 或 pip-audit 以检查已知漏洞。

部署前检查清单

  • .actor/actor.json 存在,并具有正确的名称和描述
  • .actor/actor.json 针对 @apify/json_schemas(actor.schema.json)验证通过
  • .actor/input_schema.json 定义了所有必需的输入
  • .actor/input_schema.json 针对 @apify/json_schemas(input.schema.json)验证通过
  • .actor/output_schema.json 定义了输出结构(如果适用)
  • .actor/output_schema.json 针对 @apify/json_schemas(output.schema.json)验证通过
  • Dockerfile 存在且构建成功
  • Actor.init() / Actor.exit() 包装了主代码(JS/TS)
  • async with Actor: 包装了主代码(Python)
  • 通过 Actor.getInput() / Actor.get_input() 读取输入
  • 输出使用 Actor.pushData() 或键值存储
  • apify run --user-agent apify-agent-skills/apify-actorization 使用测试输入成功执行
  • README.md 存在且结构正确(介绍、功能、数据表、教程、定价、输入/输出示例)
  • 在 actor.json 的 meta 部分设置了 generatedBy

MCP 工具

Apify MCP

如果配置了 Apify MCP 服务器,请使用以下工具获取文档:

  • search-apify-docs - 搜索文档
  • fetch-apify-docs - 获取完整的文档页面

否则,MCP 服务器 URL:https://mcp.apify.com/?tools=docs。

Playwright MCP(调试)

Playwright MCP 服务器是调试与 Web 交互的 Actor 的有用工具——它允许代理驱动真实的浏览器来检查页面、捕获选择器和重现问题。

使用 Claude Code CLI 安装:

claude mcp add playwright npx @playwright/mcp@latest

或手动将其添加到您的 MCP 配置中:

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["@playwright/mcp@latest"]
    }
  }
}

资源

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

Create, modify, debug, and deploy Apify Actors, and write their input and output schemas. Use when building an Actor from scratch, changing or troubleshooting Actor code, generating or updating .actor schema files, or pushing an Actor to the Apify platform. To wrap an existing non-Actor project, use apify-actorization instead.

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.

相关技能