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

193
Visualizações
How to scrape part of a page node.js

I'm fairly new to coding and I don't understand why my code isn't working. It is suppose to output "Dominus Empyreus" Though it only outputs []

Here is my current code:

const axios = require('axios'); 
const cheerio = require('cheerio'); 
 
const extractLinks = $ => [ 
    ...new Set( 
        $('.border-bottom item-name-container') // Select pagination links 
            .toArray() // Convert cheerio object to array 
    ), 
]; 
 
axios.get('https://www.roblox.com/catalog/21070012/Dominus-Empyreus').then(({ data }) => { 
    const $ = cheerio.load(data); // Initialize cheerio 
    const stuff = extractLinks($); 
 
    console.log(stuff); 
    // ['Dominus Empyreus'] 
});

Any help is appreciated! Thanks.

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

This is the element you are trying to select.

<div class="border-bottom item-name-container">

You have written:

.border-bottom item-name-container

Which consists of:

  • A class selector (for class="border-bottom")
  • A descendant combinator
  • A type selector (for <item-name-container>)

What you need is:

  • A class selector (for class="border-bottom")
  • Another class selector (for class="item-name-container")
  • No descendant combinator (because you are targeting two features of the same element, not one element that is a descendant of the other).

Such:

.border-bottom.item-name-container
about 4 years ago · Santiago Gelvez Relatório

0

An alternative solution is to use the full selector path to the element directly that you want to scrape from a web page as such:

const axios = require('axios'); 
const cheerio = require('cheerio'); 

const extractLinks = $ => [
    ...new Set( 
        $("#item-container > div.remove-panel.section-content.top-section > div.border-bottom.item-name-container > h1") // Select pagination links 
            .toArray() // Convert cheerio object to array 
    ), 
]; 

axios.get('https://www.roblox.com/catalog/21070012/Dominus-Empyreus').then(({ data }) => { 
    const $ = cheerio.load(data); // Initialize cheerio 
    const stuff = extractLinks($);

    console.log(stuff[0].children[0].data);
    // ['Dominus Empyreus'] 
});

A quick and simple way of obtaining a full selector path is using the F12 developer's console on your browser, right-click the element -> Copy -> Copy Selector.

img

In this case, the selector for this <h1> element is:

#item-container > div.remove-panel.section-content.top-section > div.border-bottom.item-name-container > h1

The one thing to note is that this solution will only work if the selector path is the exact same on every page you wish to scrape.

about 4 years ago · Santiago Gelvez 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