Created
December 11, 2017 00:22
-
-
Save kevinkassimo/8aebb750fc5ccb09debaf9e9c369bd5d to your computer and use it in GitHub Desktop.
Fetch crypto price with Puppeteer (experimental script)
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 puppeteer = require('puppeteer'); | |
const fs = require('fs'); | |
const currenciesJSON = fs.readFileSync('./config.json'); | |
const currencies = JSON.parse(currenciesJSON).currencies; | |
puppeteer.launch({devtools: false}).then(async browser => { | |
for (let currency of currencies) { | |
const page = await browser.newPage(); | |
if (currency == '') { | |
continue; | |
} | |
await page.setJavaScriptEnabled(false); // speed up stuffs | |
await page.goto(`https://coinmarketcap.com/currencies/${currency}`); | |
try { | |
let price = await page.$eval('#quote_price', el => el.getAttribute('data-usd')); | |
console.log(`====================== | |
Currency: ${currency} | |
Price: \$${price}`); | |
} catch(_) { | |
console.log(`ERROR: currency '${currency}' does not exist.`); | |
} | |
await page.close(); | |
} | |
console.log("======================"); | |
await browser.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment