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

208
Visualizações
Why can't I scrape for specific information of this webpage? (with node.js and jQuery)

So I want to scrape for specific information about news from this website: https://24.hu/fn/gazdasag/2022/07/23/igy-lehet-olcsobb-a-maganorvos-az-egeszsegpenztarbol/

I'm working on creating a web crawler and I need the new's title and the content. I use node.js, javascript and jQurey. And I've also created tests for that and I can reach the title, but I can't get the context. Despite of the fact that I've tried the code in the console of the browser, and it works well there.

This would be the code in the console: $('[data-io-article-url="https://24.hu/fn/gazdasag/2022/07/23/igy-lehet-olcsobb-a-maganorvos-az-egeszsegpenztarbol/"]').text().trim();

And I get the following answer: `A pandémia az életünk számos területét befolyásolta, de talán semmit sem annyira közvetlenül, mint az orvoshoz járási szokásainkat. Az elmúlt két évben tanúi lehettünk annak, hogy a végletekig leterhelt állami egészségügyi rendszer egyre nehezebben bírja a betegek megfelelő ellátását. Ráadásul úgy tűnik, hogy a járványt még korántsem tudhatjuk magunk mögött..... In my VsCode I saved the html of the webpage and created the follolwing test:

const fs = require("fs");
const parser = require("../24Parser");

const newsPage1Html = fs.readFileSync("tests/html/test.html");

let parserResult;

beforeAll(() => {
    parserResult = parser(newsPage1Html, );
})

describe("parsing html news page correctly", () => {
    test("title", () => {
        expect(parserResult.title).toBe("Így lehet olcsóbb a magánorvos az egészségpénztárból");
    })
    test("content", () => {
         expect(parserResult.content).toBe("lskl");
    })
})

And my parser looks like this:

const cheerio = require("cheerio");

function parseAll(html, page) {
    const $ = cheerio.load(html);

    const title = $('[itemprop="headline"]').text().trim();
    
    //const content = $(`[data-io-article-url="${page}"]`).text().trim();
    const content = $('[data-io-article-url="https://24.hu/fn/gazdasag/2022/07/23/igy-lehet-olcsobb-a-maganorvos-az-egeszsegpenztarbol/"]').text().trim();

    return { title, content}
}

module.exports = parseAll;

So I use exactly the same code and I get nothing in case of the content. Why is that? I would like to create it dynamic later, that's why the commented line.

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