forked from MRHRTZ/Js-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mobile-legend-scrape.js
115 lines (112 loc) · 5.98 KB
/
mobile-legend-scrape.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const { default: Axios } = require('axios')
const cheerio = require('cheerio')
function herolist(){
return new Promise((resolve, reject) => {
Axios.get('https://mobile-legends.fandom.com/wiki/Mobile_Legends:_Bang_Bang_Wiki')
.then(({ data }) => {
const $ = cheerio.load(data)
let data_hero = []
let url = []
$('div > div > span > span > a').get().map((result) => {
const name = decodeURIComponent($(result).attr('href').replace('/wiki/',''))
const urln = 'https://mobile-legends.fandom.com' + $(result).attr('href')
data_hero.push(name)
url.push(urln)
})
resolve({ status: 200, hero: data_hero })
}).catch((e) => reject({ status: 404, message: e.message }))
})
}
function herodetails(name) {
return new Promise((resolve, reject) => {
var splitStr = name.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
const que = splitStr.join(' ')
Axios.get('https://mobile-legends.fandom.com/wiki/' + que)
.then(({ data }) => {
const $ = cheerio.load(data)
let mw = []
let attrib = []
let skill = []
const name = $('#mw-content-text > div > div > div > div > div > div > table > tbody > tr > td > table > tbody > tr > td > font > b').text()
$('.mw-headline').get().map((res) => {
const mwna = $(res).text()
mw.push(mwna)
})
$('#mw-content-text > div > div > div > div > div > div > table > tbody > tr > td').get().map((rest) => {
const haz = $(rest).text().replace(/\n/g,'')
attrib.push(haz)
})
$('#mw-content-text > div > div > div > div > div > div > table > tbody > tr > td > div.progressbar-small.progressbar > div').get().map((rest) => {
skill.push($(rest).attr('style').replace('width:',''))
})
Axios.get('https://mobile-legends.fandom.com/wiki/' + que + '/Story')
.then(({ data }) => {
const $ = cheerio.load(data)
let pre = []
$('#mw-content-text > div > p').get().map((rest) => {
pre.push($(rest).text())
})
const story = pre.slice(3).join('\n')
const items = []
const character = []
$('#mw-content-text > div > aside > section > div').get().map((rest) => {
character.push($(rest).text().replace(/\n\t\n\t\t/g, '').replace(/\n\t\n\t/g,'').replace(/\n/g,''))
})
$('#mw-content-text > div > aside > div').get().map((rest) => {
items.push($(rest).text().replace(/\n\t\n\t\t/g, '').replace(/\n\t\n\t/g,'').replace(/\n/g,''))
})
const img = $('#mw-content-text > div > aside > figure > a').attr('href')
const chara = character.slice(0,2)
const result = {
status: 200,
hero_name: name + ` ( ${mw[0].replace('CV:',' CV:')} )`,
entrance_quotes: attrib[2].replace('Entrance Quotes','').replace('\n',''),
hero_feature: attrib[attrib.length - 1].replace('Hero Feature',''),
image: img,
items: items,
character: {
chara
},
attributes: {
movement_speed: attrib[12].replace('● Movement Speed',''),
physical_attack: attrib[13].replace('● Physical Attack',''),
magic_power: attrib[14].replace('● Magic Power',''),
attack_speed: attrib[15].replace('● Attack Speed',''),
physical_defense: attrib[16].replace('● Physical Defense',''),
magic_defense: attrib[17].replace('● Magic Defense',''),
basic_atk_crit_rate: attrib[18].replace('● Basic ATK Crit Rate',''),
hp: attrib[19].replace('● HP',''),
mana: attrib[20].replace('● Mana',''),
ability_crit_rate: attrib[21].replace('● Ability Crit Rate',''),
hp_regen: attrib[22].replace('● HP Regen',''),
mana_regen: attrib[23].replace('● Mana Regen','')
},
price: {
battle_point: mw[1].split('|')[0].replace(/ /g,''),
diamond: mw[1].split('|')[1].replace(/ /g,''),
hero_fragment: mw[1].split('|')[2] ? mw[1].split('|')[2].replace(/ /g,'') : 'none'
},
role: mw[2],
skill: {
durability: skill[0],
offense: skill[1],
skill_effects: skill[2],
difficulty: skill[3]
},
speciality: mw[3],
laning_recommendation: mw[4],
release_date: mw[5],
background_story: story
}
resolve(result)
}).catch((e) => reject({ status: 404, message: e.message }))
}).catch((e) => reject({ status: 404, message: e.message }))
})
}
// herolist()
herodetails('Gatotkaca')
.then(console.log)
.catch(console.log)