又一款功能强大的浏览器自动化 AI 工具Stagehand,已狂揽了 14.3kStar!


为什么选择Stagehand?

大多数现有的浏览器自动化工具要么要求您使用Selenium、Playwright或Puppeteer等框架编写底层代码,要么使用在生产环境中可能不可预测的高级代理。通过让开发者选择何时使用代码或自然语言,Stagehand成为生产环境中浏览器自动化的理想选择。

  1. 选择何时使用代码或自然语言:在需要导航不熟悉的页面时使用AI,在明确知道要做什么时使用代码(Playwright)。

  2. 预览和缓存操作:Stagehand允许您在运行AI操作之前预览它们,并帮助您轻松缓存可重复的操作以节省时间和令牌。

  3. 一行代码集成计算机使用模型:Stagehand允许您通过一行代码将OpenAI和Anthropic的最新技术(SOTA)计算机使用模型集成到浏览器中。

示例

以下是如何使用Stagehand构建一个示例浏览器自动化:

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line// 在页面对象上使用Playwright函数const page = stagehand.page;await page.goto("https://github.com/browserbase");
// 使用act()执行单个操作await page.act("点击stagehand仓库");
// 使用计算机使用代理执行更大的操作const agent = stagehand.agent({    provider: "openai",    model: "computer-use-preview",});await agent.execute("跳转到最新的PR");
// 使用extract()从页面中提取数据const { author, title } = await page.extract({  instruction: "提取PR的作者和标题",  schema: z.object({    author: z.string().describe("PR作者的用户名"),    title: z.string().describe("PR的标题"),  }),});

快速开始

通过一行代码开始使用Stagehand,或查看我们的快速入门指南获取更多信息:

ounter(linenpx create-browser-app


观看Anirudh演示如何使用create-browser-app创建Stagehand项目!


从源代码构建和运行

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(linegit clone https://github.com/browserbase/stagehand.gitcd stagehandpnpm installpnpm playwright installpnpm run buildpnpm run example # 运行位于./examples/example.ts的空白脚本pnpm run example 2048 # 运行位于./examples/2048.ts的2048示例

当您拥有LLM提供商的API密钥和Browserbase凭据时,Stagehand效果最佳。要将这些添加到您的项目中,请运行:

ounter(lineounter(linecp .env.example .envnano .env # 编辑.env文件以添加API密钥

项目地址

https://github.com/browserbase/stagehand/blob/main/README.md




扫码加入技术交流群,备注「开发语言-城市-昵称

(文:GitHubStore)

发表评论