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

153
Vistas
Web Scraping using Node JS Puppeteer

I want to scrape some vessel details using Node Js and Puppeteer. When I try to scrape data , the result is showing null. I don't have any idea about why I am getting output like this. Here is my code.

index.js

const puppeteer = require("puppeteer");
const Scraper = require("./scrapers/class-based");

/**
 * Run Scraper
 */
(async () => {
  let browser;
  let page;

  try {
    browser = await puppeteer.launch({
      headless: false
    });

    page = await browser.newPage();

    await new Scraper(browser, page).main();
  } catch (error) {
    console.log(error.stack || error);
  }

  await browser.close();
})();

class.js

const writeFileSync = require("fs").writeFileSync;

/**
 * @class Scraper
 */
module.exports = class Scraper {
  /**
   * @constructor
   */
  constructor(browser, page) {
    this.browser = browser;
    this.page = page;

    this.standings = [];
    this.url = "https://www.myshiptracking.com/vessels";
  }

  
    // @method main
   
  async main() {
    await this.page.goto(this.url, { waitUntil: "domcontentloaded" });

    this.standings = await this.page.evaluate(() =>
      Array.from(document.querySelectorAll("tbody > tr")).map(team => [
        team.querySelector("td:nth-child(4)").getAttribute("data-value"),
        team.querySelector("td:nth-child(6)").getAttribute("data-value")
      ])
    );

    this.writeToJson();
  }

  /**
   * @method writeToJson
   */
  writeToJson() {
    writeFileSync("./data/standings.json", JSON.stringify(this.standings));
  }
};

output: Standings.json

[[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null],[null,null]]

I am new to Node JS and Scraping. I followed tutorial and got answer like this. If anyone could help it would be really helpful. Thanks.

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