Skip to content

Instantly share code, notes, and snippets.

@piyukore06
Last active July 1, 2019 19:18
Show Gist options
  • Save piyukore06/6a5ef20e3fb1b32cbe4ff7d2815d13da to your computer and use it in GitHub Desktop.
Save piyukore06/6a5ef20e3fb1b32cbe4ff7d2815d13da to your computer and use it in GitHub Desktop.
Scraping with Puppeteer
const puppeteer = require('puppeteer');
const fa = require('fs');
let scrape = (async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://unicode.org/emoji/charts/full-emoji-list.html');
const result = await page.evaluate(() => {
let data = []
document.querySelectorAll('table tr').forEach(node => {
const code = node.querySelector('.code a')
const name = node.querySelector('.name')
if (code) {
data.push({
code: code.innerHTML.replace(' ', '').split('U+').filter(Boolean).join('_').toLowerCase(),
name: name.innerHTML
});
}
})
return data
});
await browser.close();
return result;
});
scrape().then(data => {
fs.writeFile('emoji-list.json', JSON.stringify(value), 'utf8', () => {
console.log('DONE!!')
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment