什么是舞台工?
Stagehand 是一个用于自然语言和代码控制网页浏览器的浏览器自动化框架。通过结合人工智能的力量与代码的精准,Stagehand使网络自动化变得灵活、易维护且真正可靠。
为什么是舞台工?
大多数现有的浏览器自动化工具要么要求你在 Selenium、Playwright 或 Puppeteer 等框架中编写低级代码,要么使用在生产环境中可能不可预测的高级代理。通过让开发者选择用代码写什么,而不是自然语言(并弥合两者之间的差距),Stagehand成为浏览器自动化在生产环境中的自然选择。
-
选择何时编写代码与自然语言:当你想浏览陌生页面时使用人工智能,明确自己想做什么时使用代码。
-
从AI驱动转向可重复的工作流程:Stagehand允许你在执行AI动作前预览,还能帮助你轻松缓存可重复动作,节省时间和代币。
-
写一次,永远运行:Stagehand的自动缓存结合自愈功能,能记住之前的作,运行时不依赖LLM推断,并且知道何时在网站变更和自动化失效时调用AI。
开始
用一行代码开始使用Stagehand,或者查看我们的快速入门指南了解更多信息:
npx create-browser-app
例
以下是用 Stagehand 构建示例浏览器自动化的方法:
// Stagehand's CDP engine provides an optimized, low level interface to the browser built for automation
const page = stagehand.context.pages()[0];
await page.goto("https://github.com/browserbase");
// Use act() to execute individual actions
await stagehand.act("click on the stagehand repo");
// Use agent() for multi-step tasks
const agent = stagehand.agent();
await agent.execute("Get to the latest PR");
// Use extract() to get structured data from the page
const { author, title } = await stagehand.extract(
"extract the author and title of the PR",
z.object({
author: z.string().describe("The username of the PR author"),
title: z.string().describe("The title of the PR"),
}),
);
文档
请访问 docs.stagehand.dev 查看完整文档。
构建并运行源代码
git clone https://github.com/browserbase/stagehand.git
cd stagehand
pnpm install
pnpm run build
pnpm run example # run the blank script at ./examples/example.ts
Stagehand最好是当你有LLM提供商的API密钥和Browserbase凭证时。要将这些添加到你的项目中,请运行:
cp .env.example .env
nano .env # Edit the .env file to add API keys


没有回复内容