Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda