Last active
July 1, 2019 19:18
-
-
Save piyukore06/6a5ef20e3fb1b32cbe4ff7d2815d13da to your computer and use it in GitHub Desktop.
Scraping with Puppeteer
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 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