在 browser-use 中配置代理认证
在创建 Agent 实例的 browser_config 参数中注入代理服务器与账号密码字典。
example.py
from browser_use import Agent
from langchain_openai import ChatOpenAI
import asyncio
async def run_browser_agent():
llm = ChatOpenAI(model="gpt-4o")
# 注入美国定位的粘性住宅 IP
agent = Agent(
task="访问 example.com,搜索前沿 AI 生产力工具并提取前三名的详细介绍。",
llm=llm,
browser_config={
"headless": True,
"proxy": {
"server": "http://proxy.bytesflows.com:31112",
"username": "user-youraccount-country-us-session-agent01",
"password": "yourpassword"
}
}
)
history = await agent.run()
print("Agent 执行结束,最终输出结果:", history.final_result())
asyncio.run(run_browser_agent())