function extractObjectFromLocator(locator, options): Promise<Record<string, string | null> | null>

Extracts a structured object from a locator.

Examples

 import { extractObjectFromLocator } from "@intuned/sdk/optimized-extractors";

 await page.goto("https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html")
 const book = await extractObjectFromLocator(page.locator(".page_inner"),
   {
     entityName: "book",
     label: "book-extraction",
     entitySchema: {
       type: "object",
       required: ["name","price","reviews"],
       properties: {
         name: {
           type: "string",
           description: "book name",
         },
         price: {
           type: "string",
           description: "book price"
         },
         reviews: {
           type: "string",
           description: "Number of reviews"
         }

       }
     }
   },
 )

 console.log(book)

 // output:
 // { name: 'A Light in the Attic', price: '£51.77', reviews: '0' }

Parameters

locator: Locator

The Playwright Locator object from which to extract the data.

options

options.entityName: string

The name of the entity being extracted. it must be between 1 and 50 characters long and can only contain letters, digits, periods, underscores, and hyphens.

options.entitySchema: SimpleObjectSchema

The schema of the entity being extracted.

options.label: string

A label for this extraction process, used for billing and monitoring.

options.optionalPropertiesInvalidator?

Optional. A function to invalidate optional properties.

options.prompt?: string

Optional. A prompt to guide the extraction process.

options.strategy?: ImageStrategy | HtmlStrategy

Optional. The strategy to use for extraction, if not provided, the html strategy with claude haiku will be used.

options.variantKey?: string

Optional. A variant key for the extraction process.

Returns

Promise<Record<string, string | null> | null>

A promise that resolves to the extracted object.