I have the code below:
var request = require('request'); var cheerio = require ("cheerio"); var async= require("async"); var MyLink="www.mylink.com"; async.series([ function(callback){ request(Mylink, function (error, response, body) { if (error) return callback(error); var $ = cheerio.load(body); //Some calculations where I get NewUrl variable... TheUrl=NewUrl; callback(); }); }, function(callback){ for (var i = 0; i <=TheUrl.length-1; i++) { var url = 'www.myurl.com='+TheUrl[i]; request(url, function(error, resp, body) { if (error) return callback(error); var $ = cheerio.load(body); //Some calculations again... callback(); }); }; } ], function(error){ if (error) return next(error); });
Does anyone have a suggestion about how I can delay each loop iteration in the for loop
? Say, the code waits 10 seconds after each iteration is complete. I tried setTimeout
but didn't manage that to work.