Skip to content

Instantly share code, notes, and snippets.

@eugeniosegala eugeniosegala/parse-dom-puppeteer.js Secret
Last active Apr 10, 2019

Embed
What would you like to do?
parse dom puppeteer
const products = await page.evaluate(() => {
const links = Array.from(document.querySelectorAll('.s-result-item'));
return links.map(link => {
if (link.querySelector(".a-price-whole")) {
return {
name: link.querySelector(".a-size-medium.a-color-base.a-text-normal").textContent,
url: link.querySelector(".a-link-normal.a-text-normal").href,
image: link.querySelector(".s-image").src,
price: parseFloat(link.querySelector(".a-price-whole").textContent.replace(/[,.]/g, m => (m === ',' ? '.' : ''))),
};
}
}).slice(0, 5);
});
console.log(products.sort((a, b) => {
return a.price - b.price;
}));
await browser.close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.