GitHunt
ME

mehdi149/browse-anything-quickstart

πŸ€– Ready-to-run Python examples for Browse Anything API. Automate web scraping, price monitoring, multi-step workflows, QA testing, and lead generation using natural language prompts.

🌐 Browse Anything Python Quickstart

Practical Python examples for using the Browse Anything AI browser agent API. No brittle selectors, no complex DOM parsingβ€”just describe what you want in natural language.

What is Browse Anything?

Browse Anything is an AI browser agent that can:

  • πŸ” Scrape any website β€” Dynamic content, SPAs, JavaScript-rendered pages
  • πŸ”„ Monitor for changes β€” Price tracking, stock alerts, content updates
  • πŸ“ Fill forms & interact β€” Multi-step workflows, checkout flows, data entry
  • πŸ” Handle authentication β€” Login flows, session management, protected content
  • πŸ“Έ Capture screenshots β€” Documentation, evidence, visual monitoring

Quick Start

1. Clone and Setup

git clone https://github.com/browse-anything/browse-anything-python-quickstart.git
cd browse-anything-python-quickstart

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Get Your API Key

  1. Sign up at browseanything.io
  2. Go to your dashboard and navigate to API Keys
  3. Generate a new API key (Enterprise tier required)
# Set your API key from browseanything.io
export BROWSE_ANYTHING_API_KEY="ba_live_your_api_key_here"

# API endpoint (default)
export BROWSE_ANYTHING_API_URL="https://platform.browseanything.io/api/v1"

⚠️ Important: Keep your API key secure! Never commit it to version control.

3. Run Your First Example

cd examples
python 01_basic_scraping.py

Examples Overview

Example Description Use Cases
01_basic_scraping.py Extract data from websites News aggregation, product catalogs, directory listings
02_website_monitor.py Detect website changes Crypto prices, stock alerts, content monitoring
03_long_interactions.py Multi-step web workflows Form wizards, checkout flows, research tasks
04_advanced_agents.py Authentication & error handling Login flows, screenshot capture, session management
05_webhooks.py Real-time notifications Async processing, pipelines, alerts
06_real_world_use_cases.py Business applications Lead gen, competitor monitoring, market research
07_qa_automation.py QA & testing automation Login tests, form validation, E2E flows, UI testing

Basic Usage

from client import BrowseAnythingClient

# Initialize client
client = BrowseAnythingClient()

# Create a task with natural language
task = client.create_task("""
    Go to https://news.ycombinator.com
    Extract the top 5 stories with title, points, and URL.
    Return as JSON.
""")

# Wait for completion
result = client.wait_for_completion(task.id)

print(result.result)  # Your extracted data
print(f"Completed in {result.execution_time_ms}ms")

API Reference

Client Initialization

from client import BrowseAnythingClient

client = BrowseAnythingClient(
    api_key="ba_live_xxx",                                    # Or set BROWSE_ANYTHING_API_KEY env var
    base_url="https://platform.browseanything.io/api/v1",     # Default endpoint
    timeout=30                                                 # Request timeout in seconds
)

πŸ’‘ Get your API key from browseanything.io dashboard.

Creating Tasks

task = client.create_task(
    prompt="Your instructions here",
    metadata={"custom": "data"},   # Optional: attach metadata
    proxy_location="us",           # Optional: us, eu, etc.
    max_steps=50                   # Optional: limit agent steps
)

Task Status

# Get current status
task = client.get_task(task_id)

# Possible statuses:
# - TaskStatus.PENDING
# - TaskStatus.RUNNING
# - TaskStatus.WAITING_FOR_INPUT
# - TaskStatus.COMPLETED
# - TaskStatus.FAILED
# - TaskStatus.CANCELLED

Waiting for Completion

result = client.wait_for_completion(
    task_id,
    poll_interval=2.0,    # Check every 2 seconds
    timeout=300,          # Max 5 minutes
    on_status_change=lambda t: print(f"Status: {t.status}")
)

Screenshots

# Get screenshot as bytes
screenshot_bytes = client.get_screenshot(task_id)

# Save to file
with open("screenshot.png", "wb") as f:
    f.write(screenshot_bytes)

Human Input

For tasks that require human decisions:

task = client.get_task(task_id)

if task.status == TaskStatus.WAITING_FOR_INPUT:
    print(f"Agent asks: {task.human_input_request}")
    response = input("Your answer: ")
    client.submit_input(task_id, response)

Cancellation

client.cancel_task(task_id)

Common Patterns

Scraping with Error Handling

from client import BrowseAnythingClient, BrowseAnythingError

client = BrowseAnythingClient()

try:
    task = client.create_task("Go to example.com and extract...")
    result = client.wait_for_completion(task.id, timeout=60)
    print(result.result)
except BrowseAnythingError as e:
    print(f"Task failed: {e}")

Batch Processing

import concurrent.futures

urls = ["https://site1.com", "https://site2.com", "https://site3.com"]

def process_url(url):
    client = BrowseAnythingClient()
    task = client.create_task(f"Go to {url} and extract the title")
    return client.wait_for_completion(task.id)

# Process in parallel
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    results = list(executor.map(process_url, urls))

Continuous Monitoring

import time
from client import BrowseAnythingClient

client = BrowseAnythingClient()
last_value = None

while True:
    task = client.create_task("Go to example.com and get the current price")
    result = client.wait_for_completion(task.id)
    
    if result.result != last_value:
        print(f"Change detected! {last_value} -> {result.result}")
        last_value = result.result
    
    time.sleep(300)  # Check every 5 minutes

Webhooks

Set up webhooks to receive real-time notifications:

# Configure via Browse Anything dashboard or API
# Events: task.created, task.completed, task.failed, task.waiting_for_input

# Example Flask handler
@app.route('/webhook', methods=['POST'])
def handle_webhook():
    event = request.json['event']
    task = request.json['task']
    
    if event == 'task.completed':
        process_result(task['result'])
    
    return {'received': True}

Tips for Effective Prompts

βœ… Good Prompts

# Specific and structured
"""
Go to https://example.com/products
Find the first 5 products in the "Electronics" category.
For each product extract:
- Name
- Price (as number without currency symbol)
- Rating (if available)
Return as a JSON array.
"""

# Clear actions and expectations
"""
1. Go to https://login.example.com
2. Enter username "testuser" in the username field
3. Enter password "testpass" in the password field
4. Click the Login button
5. After login, capture the welcome message shown
"""

❌ Avoid

# Too vague
"Get stuff from website"

# No structure specified
"Scrape all products"  # What fields? What format?

# Missing context
"Click the blue button"  # Which one? Where?

Troubleshooting

Task Timeout

Increase timeout for complex tasks:

result = client.wait_for_completion(task_id, timeout=600)  # 10 minutes

Rate Limits

Add delays between requests:

import time
for url in urls:
    process(url)
    time.sleep(1)  # 1 second between tasks

Large Results

For tasks returning large data:

task = client.create_task("""
    ...extract data...
    Return only the first 50 results.
    Summarize instead of full content if needed.
""")

Project Structure

browse-anything-python-quickstart/
β”œβ”€β”€ client.py              # API client wrapper
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ README.md             # This file
└── examples/
    β”œβ”€β”€ 01_basic_scraping.py
    β”œβ”€β”€ 02_website_monitor.py
    β”œβ”€β”€ 03_long_interactions.py
    β”œβ”€β”€ 04_advanced_agents.py
    β”œβ”€β”€ 05_webhooks.py
    └── 06_real_world_use_cases.py

License

MIT License - see LICENSE file for details.


Built with ❀️ by the Browse Anything team

mehdi149/browse-anything-quickstart | GitHunt