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.txt2. Get Your API Key
- Sign up at browseanything.io
- Go to your dashboard and navigate to API Keys
- 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.pyExamples 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.CANCELLEDWaiting 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 minutesWebhooks
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 minutesRate Limits
Add delays between requests:
import time
for url in urls:
process(url)
time.sleep(1) # 1 second between tasksLarge 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.
Links
- π Browse Anything Website - Sign up & get your API key
- π API Documentation
- π¬ Discord Community
- π Report Issues
Built with β€οΈ by the Browse Anything team