I need to get an array of elements with the same class ID, which is class = "col-lg-3 col-md-4 col-xs-4 mb-30" in my case. To then get various data from each element of this array, such as an image. This is the site for example: https://altadefinizione.sale/?s=matrix
I've tried with const feedHandle = await page.$$('.col-lg-3.col-md-4.col-xs-4.mb-30');
but the result is a handle that don't allow you to navigate to children.
Ty for the help.
Try to do all the DOM processing inside page.evaluate(), it is the simplest way:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const [page] = await browser.pages();
await page.goto('https://altadefinizione.sale/?s=matrix');
const data = await page.evaluate(() => {
const divs = document.querySelectorAll('.col-lg-3.col-md-4.col-xs-4.mb-30');
const imgSources = Array.from(divs, div => div.querySelector('img').src);
return imgSources;
});
console.log(data);
} catch (err) { console.error(err); } finally { await browser.close(); }