Credentials. You supply a model API key and every extract call costs tokens; keep keys in environment variables, not in code.
Who it is forA developer who needs a table of prices, invoices or listings from a site with no API.
The problemHand-written scrapers break whenever the page layout changes and return messy text.
The outcomeSchema-validated JSON from the page, ready to save or feed into another system.
What you need first
- Node with pnpm, Python, or Go
- Chrome installed for local runs
- A model API key such as OPENAI_API_KEY, or a Browserbase API key to use the Model Gateway
Steps
- Install with
pnpm add @browserbasehq/stagehand 'zod@~4.4.3'orpip install stagehand - Launch a local browser and create a Stagehand instance with your model and API key
- Navigate with page.goto to the page you want
- Call Stagehand.extract with an instruction such as extract every invoice in the table and a schema describing the fields
- Use the returned data, which is validated against your schema
Prompt for your agent
Using browserbase/stagehand in <TypeScript or Python>, write a script that opens <url>, extracts every <item> on the page into a schema with fields <fields>, and saves the result as JSON. Read the API key from the environment.
Caveat. Respect each site's terms of service and robots rules when you extract data.
Use this in your AI agent
Ask your agent
Using the Deduped MCP, get the setup steps for browserbase/stagehand and "Pull structured data from a site with a schema"
Add Deduped to Claude Code once
claude mcp add --transport http deduped https://dedupedai.com/mcp
Every Monday: the 5 hottest repos and exactly how to use them. Free, one email a week, unsubscribe anytime.
Get them freeShare: X LinkedIn Hacker News Email Copy link
Third-party repos we don't own. AI-written use cases can be wrong. Disclaimer