Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Getting started examples
Magnus Müller414ed0b2dc0d
diff --git a/examples/getting_started/01_basic_search.py b/examples/getting_started/01_basic_search.pyindex ccd256a6e..74f874ba2 100644--- a/examples/getting_started/01_basic_search.py+++ b/examples/getting_started/01_basic_search.py@@ -1,14 +1,3 @@-"""-Getting Started Example 1: Basic Search--This example demonstrates the most basic browser-use functionality:-- Navigate to a website-- Perform a search-- Get results--Perfect for first-time users to understand how browser-use works.-"""-import asyncioimport osimport sys@@ -20,18 +9,12 @@ from dotenv import load_dotenvload_dotenv()-from browser_use import Agent-from browser_use.llm.openai.chat import ChatOpenAI+from browser_use import Agent, ChatOpenAIasync def main():- # Initialize the modelllm = ChatOpenAI(model='gpt-4.1-mini')-- # Define a simple search tasktask = "Search Google for 'what is browser automation' and tell me the top 3 results"-- # Create and run the agentagent = Agent(task=task, llm=llm)await agent.run()diff --git a/examples/getting_started/02_form_filling.py b/examples/getting_started/02_form_filling.pyindex d9e18a687..d0a96a746 100644--- a/examples/getting_started/02_form_filling.py+++ b/examples/getting_started/02_form_filling.py@@ -21,8 +21,7 @@ from dotenv import load_dotenvload_dotenv()-from browser_use import Agent-from browser_use.llm.openai.chat import ChatOpenAI+from browser_use import Agent, ChatOpenAIasync def main():diff --git a/examples/getting_started/03_data_extraction.py b/examples/getting_started/03_data_extraction.pyindex 54344cc90..8f44a089a 100644--- a/examples/getting_started/03_data_extraction.py+++ b/examples/getting_started/03_data_extraction.py@@ -21,8 +21,7 @@ from dotenv import load_dotenvload_dotenv()-from browser_use import Agent-from browser_use.llm.openai.chat import ChatOpenAI+from browser_use import Agent, ChatOpenAIasync def main():diff --git a/examples/getting_started/04_multi_step_task.py b/examples/getting_started/04_multi_step_task.pyindex 2d64e2e58..bf9cd6a53 100644--- a/examples/getting_started/04_multi_step_task.py+++ b/examples/getting_started/04_multi_step_task.py@@ -21,8 +21,7 @@ from dotenv import load_dotenvload_dotenv()-from browser_use import Agent-from browser_use.llm.openai.chat import ChatOpenAI+from browser_use import Agent, ChatOpenAIasync def main():diff --git a/examples/integrations/browserbase_stagehand.py b/examples/integrations/browserbase_stagehand.pydeleted file mode 100644index 73764368d..000000000--- a/examples/integrations/browserbase_stagehand.py+++ /dev/null@@ -1,70 +0,0 @@-"""-EXPERIMENTAL: Integration example with Stagehand (browserbase)--This example shows how to combine browser-use with Stagehand for advanced browser automation.-Note: This requires the stagehand-py library to be installed separately:- pip install stagehand-py--The exact API may vary depending on the stagehand-py version.-Please refer to the official Stagehand documentation for the latest usage:- https://pypi.org/project/stagehand-py/- https://github.com/browserbase/stagehand-python-examples/-"""--import asyncio-import os--from dotenv import load_dotenv--load_dotenv()--from stagehand import Stagehand, StagehandConfig # type: ignore--from browser_use.agent.service import Agent---async def main():- # Configure Stagehand- # https://pypi.org/project/stagehand-py/- # https://github.com/browserbase/stagehand-python-examples/blob/main/agent_example.py- # Note: This example requires the stagehand-py library to be installed- # pip install stagehand-py-- # Create StagehandConfig with correct parameters- # The exact parameters depend on the stagehand-py version- config = StagehandConfig( # type: ignore- apiKey=os.getenv('BROWSERBASE_API_KEY'),- projectId=os.getenv('BROWSERBASE_PROJECT_ID'),- )-- # Create a Stagehand client using the configuration object.- stagehand = Stagehand(- config=config,- model_api_key=os.getenv('OPENAI_API_KEY'),- # server_url=os.getenv('STAGEHAND_SERVER_URL'),- )-- # Initialize - this creates a new session automatically.- await stagehand.init()- print(f'\nCreated new session: {stagehand.session_id}')- print(f'🌐 View your live browser: https://www.browserbase.com/sessions/{stagehand.session_id}')-- # Check if stagehand has a page attribute- if hasattr(stagehand, 'page') and stagehand.page:- await stagehand.page.goto('https://google.com/')- await stagehand.page.act('search for openai')- else:- print('Warning: Stagehand page not available')-- # Combine with Browser Use- agent = Agent(task='click the first result', page=stagehand.page) # type: ignore- await agent.run()-- # go back and forth- await stagehand.page.act('open the 3 first links on the page in new tabs') # type: ignore-- await Agent(task='click the first result', page=stagehand.page).run() # type: ignore---if __name__ == '__main__':- asyncio.run(main())