Skip to content

Instantly share code, notes, and snippets.

@kevinkassimo
Created December 11, 2017 00:22
Show Gist options
  • Save kevinkassimo/8aebb750fc5ccb09debaf9e9c369bd5d to your computer and use it in GitHub Desktop.
Save kevinkassimo/8aebb750fc5ccb09debaf9e9c369bd5d to your computer and use it in GitHub Desktop.
Fetch crypto price with Puppeteer (experimental script)
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