const item = await page.extract({
    instruction: "extract the price of the item",
    schema: z.object({
      price: z.number(),
    }),
  });

  const price = item.price; // `item` has schema { price: number }

extract() grabs structured text from the current page using zod. Given instructions and schema, you will receive structured data.

We strongly suggest you set useTextExtract to true if you are extracting data from a longer body of text.

Arguments: ExtractOptions<T extends z.AnyZodObject>

instruction
string
required

Provides instructions for extraction

schema
z.AnyZodObject
required

Defines the structure of the data to extract

useTextExtract
boolean

This method converts the page to text, which is much cleaner for LLMs than the DOM. However, it may not work for use cases that involve DOM metadata elements.

modelName
AvailableModel

Specifies the model to use

modelClientOptions
object

Configuration options for the model client. See ClientOptions.

domSettleTimeoutMs
number

Timeout in milliseconds for waiting for the DOM to settle

Returns: Promise<ExtractResult<T extends z.AnyZodObject>>

Resolves to the structured data as defined by the provided schema.