Skip to content

Instantly share code, notes, and snippets.

@uratmangun
Last active December 26, 2024 01:49
Show Gist options
  • Save uratmangun/dbcbd21b883db7ad43895582288a5c2e to your computer and use it in GitHub Desktop.
Save uratmangun/dbcbd21b883db7ad43895582288a5c2e to your computer and use it in GitHub Desktop.
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