Skip to main content
The 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

instruction
string
required
Natural language description of what data to extract.
schema
ZodSchema
Optional Zod schema for structured, typed output. Without a schema, returns a string.

Why Use Schemas?

Schemas provide three key benefits:
  1. Type Safety: Get full TypeScript autocompletion and type checking
  2. Validation: Ensures the AI returns data in the correct format
  3. 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

Good: “extract the price shown next to the ‘Buy Now’ button”Bad: “get the price”
Don’t create overly complex schemas for simple data. If you only need a single value:

Next Steps

page.ai()

Perform actions before extracting

page.perform()

Single-action execution