Last active
December 26, 2024 01:49
-
-
Save uratmangun/dbcbd21b883db7ad43895582288a5c2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getAllItems(page) { | |
const products = await page.$$eval('div.list-product-items', (productElements) => { | |
return productElements.map(productElement => { | |
const titleElement = productElement.querySelector('p.product_name'); | |
const priceElement = productElement.querySelector('p.price span'); | |
const imageElement = productElement.querySelector('img'); | |
const availabilityElement = productElement.querySelector('.availability-label'); | |
const title = titleElement?.textContent?.trim() || null; | |
const price = priceElement?.textContent?.trim() || null; | |
const imageLink = imageElement?.src || null; | |
const available = !availabilityElement; | |
return { | |
title: title, | |
price: price, | |
imageLink: imageLink, | |
available: available | |
}; | |
}); | |
}); | |
return products; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment