Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

added new getting_started examples

Saurav Panda99980c6f12b5
diff --git a/examples/getting_started/01_basic_search.py b/examples/getting_started/01_basic_search.py
new file mode 100644
index 000000000..76daeae3d
--- /dev/null
+++ b/examples/getting_started/01_basic_search.py
@@ -0,0 +1,40 @@
+"""
+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 asyncio
+import os
+import sys
+
+# Add the parent directory to the path so we can import browser_use
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+
+from dotenv import load_dotenv
+
+load_dotenv()
+
+from browser_use import Agent
+from browser_use.llm.openai.chat import ChatOpenAI
+
+
+async def main():
+ # Initialize the model
+ llm = ChatOpenAI(model='gpt-4o-mini')
+
+ # Define a simple search task
+ task = "Search Google for 'what is browser automation' and tell me the top 3 results"
+
+ # Create and run the agent
+ agent = Agent(task=task, llm=llm)
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/getting_started/02_form_filling.py b/examples/getting_started/02_form_filling.py
new file mode 100644
index 000000000..3be128861
--- /dev/null
+++ b/examples/getting_started/02_form_filling.py
@@ -0,0 +1,52 @@
+"""
+Getting Started Example 2: Form Filling
+
+This example demonstrates how to:
+- Navigate to a website with forms
+- Fill out input fields
+- Submit forms
+- Handle basic form interactions
+
+This builds on the basic search example by showing more complex interactions.
+"""
+
+import asyncio
+import os
+import sys
+
+# Add the parent directory to the path so we can import browser_use
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+
+from dotenv import load_dotenv
+
+load_dotenv()
+
+from browser_use import Agent
+from browser_use.llm.openai.chat import ChatOpenAI
+
+
+async def main():
+ # Initialize the model
+ llm = ChatOpenAI(model='gpt-4o-mini')
+
+ # Define a form filling task
+ task = """
+ Go to https://httpbin.org/forms/post and fill out the contact form with:
+ - Customer name: John Doe
+ - Telephone: 555-123-4567
+ - Size: Medium
+ - Topping: cheese
+ - Delivery time: now
+ - Comments: This is a test form submission
+
+ Then submit the form and tell me what response you get.
+ """
+
+ # Create and run the agent
+ agent = Agent(task=task, llm=llm)
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/getting_started/03_data_extraction.py b/examples/getting_started/03_data_extraction.py
new file mode 100644
index 000000000..146cb9446
--- /dev/null
+++ b/examples/getting_started/03_data_extraction.py
@@ -0,0 +1,51 @@
+"""
+Getting Started Example 3: Data Extraction
+
+This example demonstrates how to:
+- Navigate to a website with structured data
+- Extract specific information from the page
+- Process and organize the extracted data
+- Return structured results
+
+This builds on previous examples by showing how to get valuable data from websites.
+"""
+
+import asyncio
+import os
+import sys
+
+# Add the parent directory to the path so we can import browser_use
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+
+from dotenv import load_dotenv
+
+load_dotenv()
+
+from browser_use import Agent
+from browser_use.llm.openai.chat import ChatOpenAI
+
+
+async def main():
+ # Initialize the model
+ llm = ChatOpenAI(model='gpt-4o-mini')
+
+ # Define a data extraction task
+ task = """
+ Go to https://quotes.toscrape.com/ and extract the following information:
+ - The first 5 quotes on the page
+ - The author of each quote
+ - The tags associated with each quote
+
+ Present the information in a clear, structured format like:
+ Quote 1: "[quote text]" - Author: [author name] - Tags: [tag1, tag2, ...]
+ Quote 2: "[quote text]" - Author: [author name] - Tags: [tag1, tag2, ...]
+ etc.
+ """
+
+ # Create and run the agent
+ agent = Agent(task=task, llm=llm)
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())
diff --git a/examples/getting_started/04_multi_step_task.py b/examples/getting_started/04_multi_step_task.py
new file mode 100644
index 000000000..e54302bb0
--- /dev/null
+++ b/examples/getting_started/04_multi_step_task.py
@@ -0,0 +1,55 @@
+"""
+Getting Started Example 4: Multi-Step Task
+
+This example demonstrates how to:
+- Perform a complex workflow with multiple steps
+- Navigate between different pages
+- Combine search, form filling, and data extraction
+- Handle a realistic end-to-end scenario
+
+This is the most advanced getting started example, combining all previous concepts.
+"""
+
+import asyncio
+import os
+import sys
+
+# Add the parent directory to the path so we can import browser_use
+sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+
+from dotenv import load_dotenv
+
+load_dotenv()
+
+from browser_use import Agent
+from browser_use.llm.openai.chat import ChatOpenAI
+
+
+async def main():
+ # Initialize the model
+ llm = ChatOpenAI(model='gpt-4o-mini')
+
+ # Define a multi-step task
+ task = """
+ I want you to research Python web scraping libraries. Here's what I need:
+
+ 1. First, search Google for "best Python web scraping libraries 2024"
+ 2. Find a reputable article or blog post about this topic
+ 3. From that article, extract the top 3 recommended libraries
+ 4. For each library, visit its official website or GitHub page
+ 5. Extract key information about each library:
+ - Name
+ - Brief description
+ - Main features or advantages
+ - GitHub stars (if available)
+
+ Present your findings in a summary format comparing the three libraries.
+ """
+
+ # Create and run the agent
+ agent = Agent(task=task, llm=llm)
+ await agent.run()
+
+
+if __name__ == '__main__':
+ asyncio.run(main())