๐ป Code Examples
Practical examples to help you get started with Browser AI Agent. Copy, modify, and run these examples to learn automation techniques.
Basic Usage
Simple examples to get you started with browser automation. Perfect for beginners learning the basics.
import asyncio
from browser_ai_agent import execute_browser_task
async def main():
result = await execute_browser_task(
"Go to Google and search for 'Python programming'",
headless=False,
debug=True
)
print(f"Success: {result.success}")
asyncio.run(main())
Advanced Workflows
Complex multi-step automation workflows with error handling, data extraction, and parallel processing.
async def advanced_workflow():
async with BrowserAIAgent(debug=True) as agent:
tasks = [
"Navigate to Amazon and search for 'wireless headphones'",
"Filter results by customer rating (4+ stars)",
"Extract top 5 products with prices and ratings"
]
results = await agent.execute_multiple_tasks(tasks)
return results
E-commerce Automation
Automate product research, price monitoring, and competitive analysis across multiple e-commerce platforms.
async def monitor_prices():
products = [
"https://amazon.com/product/123",
"https://ebay.com/item/456"
]
async with BrowserAIAgent() as agent:
for url in products:
result = await agent.execute_task(
f"Extract product name, price, and rating from {url}"
)
print(f"Product data: {result.extracted_data}")
Form Automation
Intelligent form filling with validation, error handling, and multi-step form workflows.
async def fill_contact_form():
form_data = {
"name": "John Doe",
"email": "john@example.com",
"message": "Hello from Browser AI Agent!"
}
async with BrowserAIAgent() as agent:
await agent.navigate_to("https://example.com/contact")
result = await agent.execute_task(
f"Fill out the contact form with: {form_data}"
)
Data Scraping
Intelligent web scraping with AI-powered content extraction, pagination handling, and structured data output.
async def scrape_news_articles():
async with BrowserAIAgent() as agent:
result = await agent.execute_task("""
Go to Hacker News and extract:
- Article titles
- URLs
- Points/votes
- Number of comments
From the first 2 pages
""")
return result.extracted_data
Testing Automation
Automated testing workflows with AI-powered validation, regression testing, and comprehensive reporting.
async def test_website_functionality():
test_cases = [
"Verify login form accepts valid credentials",
"Check that navigation menu works correctly",
"Validate search functionality returns results"
]
async with BrowserAIAgent() as agent:
for test in test_cases:
result = await agent.execute_task(test)
assert result.success, f"Test failed: {test}"
Want to contribute examples?
Share your automation workflows with the community. Submit your examples via GitHub!