-
Notifications
You must be signed in to change notification settings - Fork 0
/
emojis.js
30 lines (24 loc) · 904 Bytes
/
emojis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require('fs');
const path = require('path');
const request = require('request');
const cheerio = require('cheerio');
function download(uri, filename, callback) {
console.log(uri);
request.head(uri, (err, res, body) => {
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(path.join(__dirname, 'images', filename))).on('close', callback);
});
};
const url = 'http://emojipedia.org/microsoft/windows-10-anniversary-update/';
request(url, (err, resp, body) => {
$ = cheerio.load(body);
const images = $('.emoji-grid img');
$(images).each((i, img) => {
const url = $(img).attr('data-src');
const alt = $(img).attr('alt');
if (url !== undefined && alt !== undefined) {
download(url, `${i}_${alt}.png`, () => console.log(i));
}
});
});