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

176
Views
Detener el bucle después del elemento n-th - titiritero

¿Cómo puedo detener el bucle después del quinto enlace?

este es mi codigo

 await page.goto('https://old.reddit.com',{"waitUntil" : "networkidle0"}); const a_elems = await page.$$('.thumbnail'); for (var i=0; i<a_elems.length; i++) { const elem = a_elems[i]; const href = await page.evaluate(e => e.href, elem); const newPage = await browser.newPage(); await newPage.goto(href,{"waitUntil" : "networkidle0"}); }

Probé nth-child pero no funciona. ¿Tienes alguna idea? ¡Gracias!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

simplemente agregue la condición en su ciclo for

 for (var i=0; i<a_elems.length && i<5; i++) { const elem = a_elems[i]; const href = await page.evaluate(e => e.href, elem); const newPage = await browser.newPage(); await newPage.goto(href,{"waitUntil" : "networkidle0"});

}

about 4 years ago · Santiago Gelvez 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!