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

435
Views
UnhandledPromiseRejectionWarning: Error: Evaluación fallida: ReferenceError: k no está definido

Estoy tratando de usar for loop. Pero se produce este error. "ReferenceError: k no está definido" ¿Cómo puedo corregir el error?

 let imageURL = []; for (let k = 1; k <= images.length; k++) { let data = await page.evaluate(() => { let innerHTML = document.querySelectorAll('#__layout > main > div.nuxt-container > div > div:nth-child(3) > div.item-container > div:nth-child(72) > div > div.body > div.image-container > ul > li')[k].innerHTML; let startIndex = innerHTML.indexOf('&quot;') + 6; let endIndex = innerHTML.lastIndexOf('&quot;'); let imageLink = innerHTML.substring(startIndex, endIndex); return { image: imageLink, }; }); imageURL.push(data); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Supongamos que está utilizando titiritero...

 var a = 3; await page.evaluate(() => { // Here you cannot use 'a', since 'a' is in the context that is different than the context where this function is going to be executed (page context) })

Si echas un vistazo a la API:

 page.evaluate(pageFunction[, ...args])

Puede ver que el primer argumento es su función que se ejecutará en el contexto de la página. Pero también puede ver que puede tener argumentos (args) que se pasarán a pageFunction.

En su lugar, debe hacer:

 var a = 4; await page.evaluate((a) => { // Now you can use outer 'a' variable through argument passed }, a);

Entonces, si tiene pocos argumentos, en consecuencia:

 await page.evaluate((k, startIndex, endIndex) => { }, k, startIndex, endIndex);
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!