Browser Use 是一个将 AI 大模型与浏览器自动化结合的框架,它颠覆了传统写脚本的思路,能让你直接用自然语言(比如“去XX网站搜一下iPhone最新价格”)来控制浏览器,替你自动完成操作 。它的核心架构建立在 Playwright 和 LangChain 之上,靠 AI 来理解和规划任务,因此即便网页结构有变化,它也有很强的自适应性 。
安装 Browser Use 与浏览器驱动:使用 pip 安装核心包,然后安装 Playwright 的浏览器驱动。
1 2
pip install browser-use playwright install
获取并配置 API Key:你需要一个 AI 模型的 API Key(如 OpenAI、DeepSeek 等)。从对应平台获取后,可以新建一个 .env 文件写入密钥,或者直接在代码里配置 。
✍️ 一个简单的例子
安装配置好后,可以创建一个 Python 脚本来体验一下。比如我们想让它找一下 browser-use 这个 GitHub 项目的 Star 数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from browser_use import Agent, Browser, ChatOpenAI import asyncio
asyncdefmain(): browser = Browser() agent = Agent( task="Find the number of stars of the browser-use repo", llm=ChatOpenAI(model='gpt-4o'), # 记得替换成你用的模型 browser=browser, ) await agent.run()
if __name__ == "__main__": asyncio.run(main())
另外,Browser Use 也提供了 WebUI 版本,让你可以在图形界面里配置模型、下达任务并观察结果,对新手更友好 。
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.