Created
February 23, 2020 23:41
-
-
Save slmcmahon/8b2de8b6bd5420cc76dd9a2cb5047496 to your computer and use it in GitHub Desktop.
Exchange Rates for USD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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