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

527
Views
Titiritero y JSHandle@node aria-label ¿Cómo?

Estoy usando titiritero para intentar acceder al atributo 'aria-label' de la consulta a continuación, pero está devolviendo resultados de tipo:

 JSHandle@node

Lo que significa que cuando intento .getAttribute('aria-label') no está definido .

Estoy tratando de obtener una lista de fechas disponibles del calendario flatpickr.

¿Alguien puede decirme cómo hacer esto correctamente?

Gracias.

 (async () => { const arias = await page.evaluate(() => { const results = document.querySelectorAll('span.flatpickr-day:not(.prevMonthDay):not(.nextMonthDay):is(.flatpickr-disabled)'); dates = {}; if (results.length) { for ( var i = 0; i < results.length; i++ ) { dates.push(results[i].getAttribute('aria-label')); } } return dates; }); })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cuando tenga problemas con la evaluate , los primeros pasos son agregar un oyente al navegador console.log s y probar el código en el navegador usted mismo.

Intentemos ejecutar el código en el propio navegador, sin Puppeteer, para que podamos ver si hay algún error:

 const results = document.querySelectorAll("div"); dates = {}; if (results.length) { // unnecessary; if results.length is 0, the loop won't run for (var i = 0; i < results.length; i++) { dates.push(results[i].getAttribute('aria-label')); } } console.log(dates);
 <div aria-label="foobar">baz</div>

Esto da Uncaught TypeError: dates.push is not a function . Probablemente quiso decir que las dates fueran una matriz, no un objeto:

 const results = document.querySelectorAll("div"); dates = []; for (var i = 0; i < results.length; i++) { dates.push(results[i].getAttribute('aria-label')); } console.log(dates);
 <div aria-label="foobar">baz</div>

Poniendo eso en Puppeteer, podemos acortarlo a:

 const puppeteer = require("puppeteer"); let browser; (async () => { browser = await puppeteer.launch(); const [page] = await browser.pages(); await page.setContent('<div aria-label="foobar">baz</div>'); const arias = await page.evaluate(() => Array.from( document.querySelectorAll("div"), e => e.getAttribute("aria-label") )); // or: //const arias = await page.$$eval("div", els => // els.map(e => e.getAttribute("aria-label")) //); console.log(arias); // => [ 'foobar' ] })() .catch(err => console.error(err)) .finally(async () => await browser.close()) ;

No tengo un flatpickr a mano, así que asumo que su selector es válido si se sustituye por "div" en el código anterior, junto con el sitio real que está raspando.

over 4 years ago · Santiago Trujillo 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!