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

168
Visualizações
javascript cannot convert undefined or null to object question

I am trying javascript for the first time and I am having this trouble with the example:

https://www.twilio.com/blog/web-scraping-and-parsing-html-with-node-js-and-cheerio

It is a web scrapper example that uses got and cheerio, both of which I have installed. But when i run the sample code it gives me 'cannot convert undefined or null to object error.

Why is that? I didn't change anything from the example at all.

the code in question:

  const $ = cheerio.load(response.body);

  $('a').each((i, link) => {
    const href = link.attribs.href;
    console.log(href);
  });
}).catch(err => {
  console.log(err);
});```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

How does your index.js file look like? I did the tutorial and my code is working. Maybe you are miss typed the url?

Here is my index.js

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

const vgmUrl = "https://www.vgmusic.com/music/console/nintendo/nes";

got(vgmUrl)
  .then((response) => {
    const $ = cheerio.load(response.body);
    $("a").each((i, link) => {
      const href = link.attribs.href;
      console.log(href);
    });
  })
  .catch((err) => {
    console.log(err);
  });
about 4 years ago · Juan Pablo Isaza Relatório
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