-
Notifications
You must be signed in to change notification settings - Fork 0
/
cheer.js
38 lines (33 loc) · 1.21 KB
/
cheer.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
31
32
33
34
35
36
37
38
const cheerio = require('cheerio');
const axios = require('axios');
const pangu = require('pangu');
const fs = require('fs');
const url = 'https://www.bilibili.com/blackboard/activity-BPU2018.html';
(async () => {
const html = await axios.get(url);
const $ = cheerio.load(html.data);
const imgs = $('.act-button-a').parent().parent().parent().map((index, el) => {
return 'https:' + $(el).attr('data-src');
}).toArray()
const spaces = $('.act-button-a').map(function() {
const url = $(this).attr('href').split('?')[0]
if (url.startsWith('https')) return url
else return 'https:' + url
}).toArray()
const names = $('.act-rich-render-content').filter(index => {
return index % 4 === 0 || index % 4 === 3;
}).map(function () { return $(this).text().trim() }).toArray();
const infos = $('.act-rich-render-content').filter(index => {
return index % 4 !== 0 && index % 4 !== 3;
}).map(function () { return pangu.spacing($(this).text().trim()) }).toArray();
const ups = [];
for (let i = 0; i< 100; ++i) {
ups.push({
name: names[i],
space: spaces[i],
info: infos[i],
img: imgs[i]
})
}
fs.writeFileSync('bilibili-top-100.json', JSON.stringify(ups), 'utf8');
})();