page.extract() method uses AI to extract structured data from web pages. You can optionally provide a Zod schema for type-safe extraction with automatic validation.
Signature
instruction- Natural language description of what data to extractschema(optional) - Zod schema for validation and type safety
Promise<ExtractResult<T>>
Installation
You’ll need to install Zod for schema-based extraction:Basic Examples
Simple Text Extraction
Extract text without a schema:Single Object Extraction
Extract a structured object with type safety:Intermediate Examples
Multiple Fields
Extract complex objects with many fields:Optional Fields
Handle optional data with Zod:Advanced Examples
Array Extraction
Extract lists of items:Nested Objects
Extract complex nested data structures:Table Extraction
Extract data from HTML tables:Zod Schema Primer
Basic Types
Optional and Nullable
Arrays and Objects
Validation
Error Handling
Handle validation errors gracefully:Best Practices
Be Specific in Instructions
Good:Design Schemas Carefully
Match your schema to the actual data structure:Handle Missing Data
Use optional fields for data that might not be present:Test with Real Pages
Always test extraction with actual pages:Common Use Cases
E-commerce Product Data
Article Metadata
Contact Information
Reviews and Ratings
Performance Tips
- Be specific - Clear instructions reduce processing time
- Use appropriate schemas - Don’t over-complicate schemas
- Extract once - Cache results instead of re-extracting
- Batch extraction - Extract multiple fields at once rather than separate calls
Limitations
Related
Natural Language Actions
Perform actions with page.act()
AI Setup
Configure AI agents and providers
Best Practices
Effective AI automation patterns
JavaScript Evaluation
Manual data extraction with evaluate()