page.extract() method pulls structured data from web pages. Define what you want using natural language and optionally enforce a schema with Zod for type-safe results.
Basic Usage
Parameters
Natural language description of what data to extract.
Optional Zod schema for structured, typed output. Without a schema, returns a string.
Why Use Schemas?
Schemas provide three key benefits:- Type Safety: Get full TypeScript autocompletion and type checking
- Validation: Ensures the AI returns data in the correct format
- Documentation: Use
.describe()to guide the AI on what each field means
Common Extraction Patterns
Product Information
Table Data
Article Content
Lists and Rankings
Error Handling
Best Practices
Be specific in your instructions
Be specific in your instructions
Good: “extract the price shown next to the ‘Buy Now’ button”Bad: “get the price”
Use descriptive schema fields
Use descriptive schema fields
Match schema complexity to page content
Match schema complexity to page content
Don’t create overly complex schemas for simple data. If you only need a single value:
Use enums for known categories
Use enums for known categories
Next Steps
page.ai()
Perform actions before extracting
page.perform()
Single-action execution