使用brower use AI 代理自动控制浏览器完成任务
第一步:终端运行命令下载 brower use
pip install browser-use
第二步: 终端运行命令下载playwright
playwright install
第三步:新建test.py代码,粘贴复制以下代码
import asyncio
import os
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
from pydantic import SecretStr
from browser_use import Agent
# dotenv
load_dotenv()
api_key = os.getenv('DEEPSEEK_API_KEY', '')
if not api_key:
raise ValueError('DEEPSEEK_API_KEY is not set')
async def run_search():
agent = Agent(
task=(
'go to bing.com and type test click search and give me the first url'
),
llm=ChatOpenAI(
base_url='https://api.deepseek.com/v1',
model='deepseek-chat',
api_key=SecretStr(api_key),
),
use_vision=False,
)
await agent.run()
if __name__ == '__main__':
asyncio.run(run_search())
第四步:新建.env文件并输入自己的key
DEEPSEEK_API_KEY=
第五步:运行python代码
参考仓库:GitHub - browser-use/browser-use: Make websites accessible for AI agents