Overview
Stagehand’sextract() method allows you to pull structured data from web pages using natural language instructions and Zod schemas for type safety.
Basic Extraction
Here’s a simple example that extracts data from a page:Structured Extraction with Zod
Use Zod schemas to get strongly-typed extraction results:Multi-Page Extraction
You can work with multiple pages and extract data from each:Complex Data Structures
Extract nested and complex data structures:Key Concepts
Natural Language Instructions
Describe what data you want to extract in plain English. Stagehand will use AI to understand and locate the information.Zod Schema Validation
Define the structure of your expected data with Zod schemas. This provides:- Type safety
- Runtime validation
- Auto-completion in TypeScript
- Clear data contracts
Page Context
When working with multiple pages, specify which page to extract from using thepage option.
Best Practices
- Be specific - Clear instructions yield better results
- Use schemas - Always define Zod schemas for structured data
- Handle errors - Extraction can fail if elements aren’t found
- Wait for content - Ensure dynamic content is loaded before extracting
Next Steps
- Learn about form filling to input data
- See multi-step automation for complex workflows
- Explore web navigation patterns