function extractObjectFromPageUsingSelectors<T>(page, extractor): Promise<ExtractObjectFromPageUsingSelectorsReturnType<T>>
Extracts an object from a web page using the specified selectors.
Type parameters
• T extends ObjectExtractor
Examples
import { extractObjectFromPageUsingSelectors, goto } from "@intuned/sdk/playwright";
await goto(page, 'https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html');
const book = await extractObjectFromPageUsingSelectors(page, {
name: {
selector: "h1",
selectionMethod: "all-text"
},
inStock: {
selector: ".price_color",
},
imgUrl: {
selector: "#product_gallery > div > div > div > img",
selectionMethod: {
propertyName: "src"
}
}
})
console.log(book)
// output:
// {
// name: 'A Light in the Attic',
// inStock: '£51.77',
// imgUrl: '../../media/cache/fe/72/fe72f0532301ec28892ae79a629a293c.jpg'
// }
Parameters
• page: Page
The Playwright Page object from which to extract the data.
• extractor: T
The object extractor with the selectors to use.
Returns
Promise
<ExtractObjectFromPageUsingSelectorsReturnType
<T
>>
A promise that resolves to the extracted object.