-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.js
65 lines (62 loc) · 1.94 KB
/
parser.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const {
parse
} = require('node-html-parser');
const cheerio = require('cheerio')
function parseMembers(html) {
const memberPage = parse(html)
const frame = memberPage.querySelector('#mainContent')
const timJFrame = frame.querySelectorAll('.post')[0]
const members = []
const timJProfiles = timJFrame.querySelectorAll('.profileWrap')
timJProfiles.forEach(member => {
members.push({
name: member.querySelectorAll('a')[1].structuredText.split('\n').join(' '),
imgURL: `https://jkt48.com${member.querySelector('img').attributes.src}`,
team: 'J'
})
});
const timKFrame = frame.querySelectorAll('.post')[1];
const timKProfiles = timKFrame.querySelectorAll('.profileWrap');
timKProfiles.forEach(member => {
members.push({
name: member.querySelectorAll('a')[1].structuredText.split('\n').join(' '),
imgURL: `https://jkt48.com${member.querySelector('img').attributes.src}`,
team: 'K3'
})
});
const timTFrame = frame.querySelectorAll('.post')[2];
const timTProfiles = timTFrame.querySelectorAll('.profileWrap');
timTProfiles.forEach(member => {
members.push({
name: member.querySelectorAll('a')[1].structuredText.split('\n').join(' '),
imgURL: `https://jkt48.com${member.querySelector('img').attributes.src}`,
team: 'T'
})
});
return members
}
function parseTrainees(html) {
const traineesPage = cheerio.load(html);
const trainees = []
const regex = /<br>/gm
traineesPage('table.table-member tr').each((i, e) => {
const row = cheerio.load(e);
row('td').each((i, col) => {
const td = cheerio.load(col);
const brokenName = td('p').html();
const name = brokenName.replace(regex, ' ').trim()
const imgURL = `https://jkt48.com${td('img').attr('src')}`;
const team = 'Academy';
trainees.push({
name,
imgURL,
team
})
})
})
return trainees;
}
module.exports = {
parseMembers,
parseTrainees
}