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

152
Views
Web-scraping - Cómo navegar siempre que haya un enlace disponible con Puppeteer JS

Quiero realizar un web scraping para todos los datos dentro del cuerpo de la tabla principal en la url https://data.anbima.com.br/debentures/AGRU12/agenda ... Sin embargo, como implementa la paginación, no puedo obtener eso se hizo fácilmente... Se me ocurrió el siguiente código que no funciona... Recibo el error ReferenceError: list is not defined , aunque lo he definido justo antes del ciclo while...

 const puppeteer = require('puppeteer'); const fs = require('fs'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto(`https://data.anbima.com.br/debentures/AGRU12/agenda`); await page.waitForSelector('.normal-text'); var list = []; while (true) { let nextButton; await page.evaluate(async () => { const nodeList = document.querySelectorAll( '.anbima-ui-table > tbody > tr' ); let nodeArray = [...nodeList]; nextButton = document.querySelector('.anbima-ui-pagination__next-button'); let listA = nodeArray .map((tbody) => [...tbody.children].map((td) => [...td.children])) .map((tr) => tr.map((span) => span[0].innerHTML .replace('<label class="flag__children">', '') .replace('</label>', '') ) ); list.push(listA); }); if (!nextButton) { break; } else { await page.goto(nextButton.href); } } fs.writeFile('eventDates.json', JSON.stringify(list[0], null, 2), (err) => { if (err) throw new Error('Something went wrong'); console.log('well done you got the dates'); }); await browser.close(); })();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La lista no está definida dentro de la función de devolución de llamada. Debería devolver la matriz en page.evaluate y luego usar esa matriz devuelta para empujarla a la lista.

 const list = []; while (true) { let nextButton; const listA = await page.evaluate(async () => { const nodeList = document.querySelectorAll( '.anbima-ui-table > tbody > tr' ); let nodeArray = [...nodeList]; nextButton = document.querySelector('.anbima-ui-pagination__next-button'); return nodeArray .map((tbody) => [...tbody.children].map((td) => [...td.children])) .map((tr) => tr.map((span) => span[0].innerHTML .replace('<label class="flag__children">', '') .replace('</label>', '') ) ); }); list.push(...listA);

Editar: se corrigió la última línea en mi ejemplo.

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!