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

261
Visualizações
Node.js Cheerio Live Update/Instant Refresh page on every HTML body change

I am using Axios and cheerio to scrape the cricket score website and convert its data to JSON format. But the problem is that scores and other information are not updating instantly on my API response. I want to have kind of useEffect (I know, it's React Hook and don't work in Express) functionality in my express server so that whenever the score changes on the main website, my server re-scrapes the page and show updated data.

axios(link).then(response => {
        const html = response.data
        const $ = cheerio.load(html)
        const score = []

        $('.scorecard-container', html).each(function(){
            const title = $(this).text()
            const url = link + $(this).find('a').attr('href')
            score.push({
                id: score.length + 1,
                title,
                url
            })
        })
        res.json(score)
    }).catch(err => {res.send('Something went wrong'); console.log(err)})

Thanks in Advance :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

example express endpoint

get("/stats", async (req, res) => {
  let { data } = await axios.get(someUrl)
  let $ = cheerio.load(data)
  res.json({
    title: $('title').text()
  })
})

in react

useEffect(() => {
  fetch("/stats").then(r=> r.json().then(data => setStats(data)))
}, [])
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