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

Parameters:
  • instruction - Natural language description of what data to extract
  • schema (optional) - Zod schema for validation and type safety
Returns: 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

Clear instructions lead to better extraction results
Good:
Bad:

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

  1. Be specific - Clear instructions reduce processing time
  2. Use appropriate schemas - Don’t over-complicate schemas
  3. Extract once - Cache results instead of re-extracting
  4. Batch extraction - Extract multiple fields at once rather than separate calls

Limitations

AI extraction has some limitations:
  • Requires API calls (adds latency and cost)
  • May not work on obfuscated or heavily JavaScript-rendered content
  • Accuracy depends on page structure and instruction clarity
  • Rate limits apply based on your AI provider

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()