I'm trying to get some information from a web page using request
to get the page and then cheerio
to traverse the DOM to the specific part I need I'm repeating this process for multiple elements in an array using array.forEach
using this code:
const cheerio = require('cheerio');
const request = require('request');
var i = 0;
var rates = [];
['AUD', 'CAD'].forEach(function(currancy){
var url = "https://www.google.com/finance/converter?a=1&from=USD&to=" + currancy
request(url , function(error, res , body){
const $ = cheerio.load(body);
var temp = $('.bld');
var rate = temp.text();
console.log(rate);
rates[i]= rate;
i++;
})
});
console.log('done');
the result I'm expecting is something like this:
1.31 AUD
1.28 CAD
done
but I'm getting this insted:
done
1.31 AUD
1.28 CAD
can you tell me why is array.forEach
not blocking my code?