Browser Use教程2026:用AI Agent自动化任何网站操作
网站没有API,但你还是要从中提取数据或填写表单。Browser-use教LLM自己操作浏览器。
Browser Use: When an LLM Learns to Click
Browser-use is the Python library that lets an LLM control a real browser - 107,502 GitHub stars as of August 2026, MIT license. Instead of writing brittle selectors for every page, you describe the goal in plain language and the model inspects the page, decides what to click, and executes it via Playwright under the hood.
The Core Idea
Traditional scraping is deterministic: find the CSS selector, extract the text. Browser-use is generative: the agent looks at the rendered page (via accessibility tree and screenshots), chooses an action, observes the result, and iterates. That is what makes it work on sites that change layout weekly - the agent re-reads the page each time instead of trusting a frozen selector.
A Working Example
from browser_use import Agent
import asyncio
async def main():
agent = Agent(
task="Log into the dashboard, download today's sales CSV, and email it to me",
llm=llm, # any model with tool calling
)
await agent.run()
asyncio.run(main())
That task - login, navigate, download, compose email - is the kind of multi-step workflow that used to require a custom Playwright script per site.
Where It Works and Where It Struggles
It excels at: form filling, multi-step purchases, extracting data from JS-heavy dashboards, and QA flows. It struggles with: pages behind aggressive bot detection (Cloudflare challenges), long-running sessions that drift, and anything requiring pixel-perfect visual judgment - though vision models have closed much of that gap in 2026.
Cost and Speed Reality
Every step is an LLM call. A 20-step workflow might consume 30-60k tokens and take 1-3 minutes. That is fine for automation and QA, too slow and too expensive for bulk scraping - which is why teams pair it with plain scrapers (like Crawlee) for volume and use browser-use for the tasks that need judgment.
FAQ
Does it work with any LLM? Yes - OpenAI, Anthropic, Gemini, and local models via Ollama all work.
Is it the same as Playwright? Playwright is the underlying driver; browser-use adds the LLM decision layer on top.
Can it handle login-protected sites? Yes, you can pass cookies or let it log in with credentials.
Is browser-use free? MIT-licensed; you pay only for the LLM calls it makes.
