function extractArrayFromPageUsingSelectors<T>(page, listExtractor): Promise<ExtractListObjectsUsingStaticSelectorsReturnType<T>>

Extracts a list of objects from a web page using the specified static selectors.

Type parameters

T extends ListStaticExtractor

Examples

 import { extractArrayFromPageUsingSelectors, goto } from "@intuned/sdk/playwright";

 await goto(page, 'https://books.toscrape.com/index.html');
 const books = await extractArrayFromPageUsingSelectors(page, {
   containerSelector: {
     selector: '//*[@id="default"]/div/div/div/div/section/div[2]/ol',
     type: "xpath"
   },
   propertySelectors: {
     name: {
       selector: "h3",
     },
     inStock: {
       selector: ".price_color",
     },
     imgUrl: {
       selector: "article > div.image_container > a > img",
       selectionMethod: {
         propertyName: "src"
       }
     }
   }
 })

 console.log(books)

 // output:
 // [
 //   {
 //   name: 'A Light in the ...',
 //   inStock: '£51.77',
 //   imgUrl: 'media/cache/2c/da/2cdad67c44b002e7ead0cc35693c0e8b.jpg'
 // },
 // {
 //   name: 'Tipping the Velvet',
 //   inStock: '£53.74',
 //   imgUrl: 'media/cache/26/0c/260c6ae16bce31c8f8c95daddd9f4a1c.jpg'
 // },
 // {
 //   name: 'Soumission',
 //   inStock: '£50.10',
 //   imgUrl: 'media/cache/3e/ef/3eef99c9d9adef34639f510662022830.jpg'
 // },
 //   {
 //     name: 'Sharp Objects',
 //     inStock: '£47.82',
 //     imgUrl: 'media/cache/32/51/3251cf3a3412f53f339e42cac2134093.jpg'
 //   },
 //   ...
 // ]

Parameters

page: Page

The Playwright Page object from which to extract the data.

listExtractor: T

The list static extractor with the selectors to use.

Returns

Promise<ExtractListObjectsUsingStaticSelectorsReturnType<T>>

A promise that resolves to the extracted list of objects.