Skip to content

Instantly share code, notes, and snippets.

@slmcmahon
Created February 23, 2020 23:41
Show Gist options
  • Save slmcmahon/8b2de8b6bd5420cc76dd9a2cb5047496 to your computer and use it in GitHub Desktop.
Save slmcmahon/8b2de8b6bd5420cc76dd9a2cb5047496 to your computer and use it in GitHub Desktop.
Exchange Rates for USD
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.x-rates.com/table/?from=USD&amount=1';
axios.get(url).then(response => {
const $ = cheerio.load(response.data);
$('table.ratesTable tr').each((i, elem) => {
const children = $(elem).children()
const country = $(children[0]).text();
const rate = $(children[1]).text();
console.log(`${country.padEnd(25, ' ')} ${rate.padStart(15, ' ')}`);
console.log(''.padEnd(41, '-'));
})
}).catch(error => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment