Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
Recorra las páginas para devolver todos los enlaces de productos

El objetivo es obtener todos los enlaces de productos de todas las páginas de la paginación. Hasta ahora he logrado imprimir información en la consola con console.log (enlaces). Sin embargo, dado que soy completamente nuevo en este campo y no tengo experiencia, tengo un problema sobre cómo devolver algún valor con el comando de retorno . return links .

Con console.log(links) recibo una advertencia: getLinks no es iterable

 const puppeteer = require('puppeteer') async function getLinks(){ const browser = await puppeteer.launch({headless: false, defaultViewport: null}); const page = await browser.newPage(); const url = "https://example.com/product-category?p=1&nidx" await page.goto(url) while(await page.$('.change-country-buttons > button:nth-child(1)')){ await page.waitForTimeout(2000); await page.keyboard.press('ArrowDown'); await page.waitForSelector('.change-country-buttons'); await page.waitForTimeout(2000); await page.click('.change-country-buttons > button:nth-child(1)'); await page.waitForTimeout(2000); } while(await page.$(".pagination .pagination--next")){ await page.waitForTimeout(2000); await page.evaluate(() => { document.querySelector(".pagination .pagination--next").scrollIntoView(); }); await page.waitForTimeout(1000); await page.waitForSelector(".pagination .pagination--next") await page.waitForTimeout(500); await page.click('.pagination .pagination--next') const links = await page.$$eval('.item__info > .mtc-link:nth-child(2)', (allAs) => { return allAs.map((a) => a.href) }); await page.waitForTimeout(1500); console.log(links) } }
 return links // Is returning links only form the first page and then the loop stops

Intenté algo con Promise.all() pero no me quedó del todo claro cómo hacerlo.

Por favor, ayuda y sé amable, ya que estoy empezando a aprender lo básico.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe crear una matriz y enviar todos los enlaces de casco de cada página a ella.

Esto probó con éxito para mí.

 const puppeteer = require('puppeteer') async function getLinks(){ const browser = await puppeteer.launch({headless: false, defaultViewport: null}); const page = await browser.newPage(); const url = "https://www.motocard.com/en/motorcycle-road-gear/helmets/precio_150-3200/full-face?p=1&nidx" var all_links = []; await page.goto(url); while(await page.$('.change-country-buttons > button:nth-child(1)')){ await page.waitForTimeout(2000); await page.keyboard.press('ArrowDown'); await page.waitForSelector('.change-country-buttons'); await page.waitForTimeout(2000); await page.click('.change-country-buttons > button:nth-child(1)'); await page.waitForTimeout(2000); } while(await page.$(".pagination .pagination--next")){ await page.waitForTimeout(2000); await page.evaluate(() => { document.querySelector(".pagination .pagination--next").scrollIntoView(); }); await page.waitForTimeout(1000); await page.waitForSelector(".pagination .pagination--next") await page.waitForTimeout(500); await page.click('.pagination .pagination--next') const links = await page.$$eval('.item__info > .mtc-link:nth-child(2)', (allAs) => { return allAs.map((a) => a.href) }); await page.waitForTimeout(1500); //console.log(links) all_links.push(...links); } return all_links; } (async ()=>{ var links = await getLinks(); console.log('done'); console.log(links); })();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!