Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
Update nodejs scraper json every X minutes

i've developed a scraper that retrieve some information for me, and i have this on heroku. it works fine except that i can't see the real-time updates (my app shows the first fetched values, not the actual one)

my code:

const axios = require('axios');
const cheerio = require('cheerio');
const express = require('express');
const PORT = process.env.PORT || 8000;

const app = express();
const myarr= []

app.get('/mylink', (req, res) =>{
  axios.get(myUrl,{
    responseEncoding: 'binary'
  })
    .then((response) => {
      const html = response.data
      const $ = cheerio.load(html)

      $('tr', html).each(function (parentIdx) {

          const title = $(this).find('a.tw-hidden.lg\\:tw-flex.font-bold.tw-items-center.tw-justify-between').text()
      
          myarr.push({
            title
           
          })
      })
  

      res.json(myarr)
    }).catch((err) => console.log(err))
})

app.listen(PORT, () => console.log(`Server avviato ed in ascolto sulla PORTA ${PORT}`))

how can i get updated results?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You cannot get immediate updated results when the site updates unless you own the website, in which case you can use websockets or a web hook. Failing that, your only other choice is to schedule a cronjob (as others have said) to check the website for changes at a specified interval (once per day, once per hour, etc.). For heroku, you can easily setup this up like so:

  1. Your script's first line needs to be #!/usr/bin/env node. The rest of it can be your code.
  2. Place your script in the /bin folder (create it if does not exist) at root level.
  3. Install the free "Heroku Scheduler" add-on in Heroku.
  4. Click on the "Heroku Scheduler" link to configure it, click on "Add Job", choose your interval, then set the run command to myScript.js so that the full command is $ myScript.js. Obviously, myScript.js referrers to whatever your script's file name is.
  5. Wait for the specified interval and check your heroku logs for the console.log output.
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda