0

I am trying to get the API response time from a website with cheerio. I have to wait first though for the site to fetch the time, though I am not sure how exactly to do that. Here is what I have tried. At the moment it does not work because it doesnt wait for the website to fetch the time.

request.get("site", function (err, res, body) {
    if (!err) {
      var $ = cheerio.load(body);
      $('.metrics-container').filter(function(){
        var data = $(this);
        var response_time_api = data.children().children().children()[1].children;
        console.log(response_time_api)
      });
    }
});

here is the image from the source am fetching

John James
  • 587
  • 3
  • 8
  • 19
  • You'll need to use something like phantomjs to scrape a site with its javascript executed – baao Aug 29 '17 at 10:10
  • From what I know though, phantomjs doesnt really know when the page has loaded, so I have to set a time to wait eg: 1s even if the page takes 10ms correct? - though I guess the browser doesnt know as well so nothing to can be done about that. – John James Aug 29 '17 at 10:13
  • Likely relevant: [How can I scrape pages with dynamic content using node.js?](https://stackoverflow.com/questions/28739098/how-can-i-scrape-pages-with-dynamic-content-using-node-js) – ggorlen Jan 02 '23 at 08:34

0 Answers0