The BrowserAgent class provides the simplest way to automate browsers with the Tessa API. It’s designed for quick scripts and straightforward automation tasks.
Copy
from tessa_sdk import BrowserAgentagent = BrowserAgent("YOUR_API_KEY")result = agent.run("Go to example.com and extract the title")
# Simple extractionresult = agent.run("Go to news.ycombinator.com and get the top story title")print(result.output)# With initial URLresult = agent.run( "Extract all product prices", initial_url="https://shop.example.com/products")# With timeoutresult = agent.run( "Complete the checkout process", timeout=120 # 2 minutes)# Check successif result.is_successful: print(f"Success: {result.output}")else: print(f"Failed: {result.error}")
# Fill a contact formresult = agent.fill_form( url="https://example.com/contact", form_data={ "name": "John Doe", "email": "john@example.com", "subject": "Product Inquiry", "message": "I'm interested in learning more about your products." })# Fill without submittingresult = agent.fill_form( url="https://example.com/signup", form_data={ "username": "testuser", "password": "secure_password" }, submit=False # Just fill, don't submit)
# Click a buttonresult = agent.click( url="https://example.com", element_description="the 'Sign Up' button in the header")# Click a linkresult = agent.click( url="https://example.com/products", element_description="the 'View Details' link for the first product")
# Screenshot visible viewportresult = agent.screenshot("https://example.com")# Full page screenshotresult = agent.screenshot( url="https://example.com/long-article", full_page=True)# The screenshot URL is in the outputscreenshot_url = result.output["screenshot_url"]print(f"Screenshot saved at: {screenshot_url}")
# ❌ Vagueagent.run("Get data")# ✅ Specificagent.run(""" Go to example.com/products and extract: - Product names - Prices (with currency) - Availability status - Product URLs Format as JSON list""")
Set Appropriate Timeouts
Copy
# Quick tasksresult = agent.extract(url, "title", timeout=30)# Complex workflowsresult = agent.run("Multi-step checkout", timeout=300)# No timeout for very long tasksresult = agent.run("Scrape entire catalog")
Use Residential IPs When Needed
Copy
# For geo-restricted or anti-bot sitesagent = BrowserAgent( api_key="YOUR_API_KEY", residential_ip=True # Use residential proxy)
Monitor Credit Usage
Copy
total_credits = 0for task in tasks: result = agent.run(task) total_credits += result.credits_used print(f"Task credits: {result.credits_used}")print(f"Total credits used: {total_credits}")