Feature Detection with Browser Use Agent
In this cookbook we'll be showing the browser use web agent and how it can infer information from the page, even when not told or prompted.
By the end of this cookbook, you'll have an idea of how versatile and "smart" your web agents can be even when given insufficient information.
Prerequisites
Before starting, make sure you have:
- A Hyperbrowser API key (sign up at hyperbrowser.ai if you don't have one, it's free)
- Python 3.9+ installed
The API key should be stored in a .env
file in the same directory as this notebook with the following format:
HYPERBROWSER_API_KEY=your_hyperbrowser_key_here
Step 1: Set up imports and env vars
import osfrom dotenv import load_dotenvfrom hyperbrowser import AsyncHyperbrowserfrom hyperbrowser.models import StartBrowserUseTaskParamsfrom IPython.display import Markdown, displayload_dotenv()
Step 2: Initialize Hyperbrowser Client
hb = AsyncHyperbrowser(api_key=os.getenv("HYPERBROWSER_API_KEY"))
Step 3: Define Product Detection Function
We instruct the agent with a simple instruction to go to a page, and get the list of products and their prices listed on the page. The agent handles all the complexity of page navigation and data extraction automatically.
async def feature_identification():resp = await hb.agents.browser_use.start_and_wait(StartBrowserUseTaskParams(task="Go to https://www.scrapingcourse.com/dashboard and get me the different products available, and their prices as listed on the website."))if resp.data is not None:return resp.data.final_resultreturn None
Step 4: Run the Agent
The site is actually behind a login page, but has the login credentials listed on it. Browser Use can identify this and use that to solve the login page by itself.
Then agent navigates to the site, identifies all product elements, extracts their names and prices, and returns the data in a readable format.
response = await feature_identification()if response is not None:display(Markdown(response))else:print("No response from the agent")
The products and their prices are: Chaz Kangeroo Hoodie $52, Teton Pullover Hoodie $70, Bruno Compete Hoodie $63, Frankie Sweatshirt $60, Hollister Backyard Sweatshirt $52, Stark Fundamental Hoodie $42, Hero Hoodie $54, Oslo Trek Hoodie $42, Abominable Hoodie $69, Mach Street Sweatshirt $62, Grayson Crewneck Sweatshirt $64, Ajax Full-Zip Sweatshirt $69
How it works
The Browser Use agent can identify important features that can help it navigate around obstacles. These obstacles could include cookie prompts, newsletter modals, and terms and condition checks among other prompts. The agent can identify when it has a visual blocker and if it's capable of bypassing that by itself. If so, it will bypass it, and proceed forward with it's provided task; in this case extracting information about the products on the page.
Key Takeaways
- Zero Parsing Logic - No need to write CSS selectors or XPath expressions
- Natural Language Instructions - Just tell the agent what you want in plain English
- Autonomous Navigation - The agent handles any login flows or page interactions seamlessly
This approach makes web scraping dramatically simpler compared to traditional methods, reducing hundreds of lines of brittle parsing code to just a few lines of stable, maintainable code.