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

181
Views
Javascript: los parámetros en una función principal no están definidos en la función secundaria

He estado buscando durante horas y todavía no entiendo cuál es el problema con mi código. Tengo una función principal llamada "req" y en esta función hay otra función de flecha llamada "datos". Cuando intento acceder a los parámetros "autor" y "colección" de la función principal, aparece un error de referencia: las variables no están definidas. Gracias por tu ayuda !

 const puppeteer = require('puppeteer'); const fs = require('fs'); function saveData (jsonData) { fs.writeFile("myData.txt", jsonData, function(err) { if (err) { console.log(err); } }); } async function req (author, collection) { // The two parameters are here : author and collection const browser = await puppeteer.launch({headless: false}); const page = await browser.newPage(); let link = 'www.myexampleurl/'+ author + '/'+ book + '/'; await page.goto(link); const data = await page.evaluate(() => { // Here's the arrow function let elements = document.querySelectorAll('span.alldetails'); let myBooks = []; for(element of elements) { myBooks.push( { authorName : author, // !!!!! UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: author is not defined collectionName : collection, // !!!!! UnhandledPromiseRejectionWarning: Error: Evaluation failed: ReferenceError: collection is not defined description : element.description } ) } return myBooks; }); saveData(JSON.stringify(data)); // A simple function that works to save the data in a text file browser.close(); }; req('john_doe', 'the_best_jd_books');
about 4 years ago · Santiago Gelvez
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!