#Looping problem using puppeteer (scraping)

1 messages · Page 1 of 1 (latest)

round pulsar
#
  try {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto(urlproduit, { waitUntil: 'networkidle2' });
    await page.setViewport({ width: 1080, height: 1024 });


    const obj = {
      title: await page.$eval('h1.page-title', element => element.innerText),
      price: await page.$eval('span.price', element => element.innerText),
      description: "hi",
      url: urlproduit
    }

    console.log(obj);
    await browser.close();

  } catch (error) {
    
    console.log(error);
   
  }
};

async function main() {

  for await (const item of data) {
    const urlproduit = item.property_url_du_produit;
    console.log(urlproduit);
    const alinea = /\/(www.alinea.com)/;
    const sklum = /\/(www.sklum.com)/;
    const electroDepot = /\/(www.electrodepot.fr)/;

    if (alinea.test(urlproduit)) {
      await scrappAlinea(urlproduit);

    } else if (sklum.test(urlproduit)) {
      await scrappSklum(urlproduit);

    } else if (electroDepot.test(urlproduit)) {

      await scrappElectrodepot(urlproduit);

    } else {
      console.log("non répertorier")
    }

  }

}

main();```
#

The error must be quite simple but I have not found 😕

#

console: https://www.electrodepot.fr/triplite-electro-depot-3x16a.html { title: 'Triplite ELECTRO DÉPÔT 3X16A', price: '349€98', description: 'hi', url: 'https://www.electrodepot.fr/triplite-electro-depot-3x16a.html' } https://www.electrodepot.fr/pile-electro-depot-alkaline-lr6-x4.html { title: 'Pile ELECTRO DÉPÔT Alcaline AA - LR6 x4', price: '349€98', description: 'hi', url: 'https://www.electrodepot.fr/pile-electro-depot-alkaline-lr6-x4.html' }

what happens is for example that it will block at the last line (which corresponds to the last JSON object) and instead of ending the program will continue to run