Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!