Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
Data are blank when scraping website (cheerio.js)

I'm trying to scrape data from a CDC website.

I'm using cheerio.js to fetch the data, and copying the HTML selector into my code, like so:

const listItems = $('#tab1_content > div > table > tbody > tr:nth-child(1) > td:nth-child(3)');

However, when I run the program, I just get a blank array. How is this possible? I'm copying the HTML selector verbatim into my code, so why is this not working? Here is a short video showing the issue: https://youtu.be/a3lqnO_D4pM

Here is my full code, along with a link were you can run the code:

const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");

// URL of the page we want to scrape
const url = "https://nccd.cdc.gov/DHDSPAtlas/reports.aspx?geographyType=county&state=CO&themeId=2&filterIds=5,1,3,6,7&filterOptions=1,1,1,1,1";

// Async function which scrapes the data
async function scrapeData() {
  try {
    // Fetch HTML of the page we want to scrape
    const { data } = await axios.get(url);
    // Load HTML we fetched in the previous line
    const $ = cheerio.load(data);
    // Select all the list items in plainlist class
    const listItems = $('#tab1_content > div > table > tbody > tr:nth-child(1) > td:nth-child(3)');
    // Stores data in array
    const dataArray = [];
    // Use .each method to loop through the elements
    listItems.each((idx, el) => {
      // Object holding data
      const dataObject = { name: ""};
      // Store the textcontent in the above object
      dataObject.name = $(el).text();
      // Populate array with data
      dataArray.push(dataObject);
    });
    // Log array to the console
    console.dir(dataArray);
  } catch (err) {
    console.error(err);
  }
}
// Invoke the above function
scrapeData();

Run the code here: https://replit.com/@STCollier/Web-Scraping#index.js

Thanks for any help.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda