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');