composition.js
1.64 KB
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
const express = require('express');
const app = express();
const logger = require('morgan');
const bodyParser = require('body-parser');
const apiRouter = express.Router();
//const axios = require("axios");
//const cheerio = require('cheerio');
const log = console.log;
const getHtml = async() => {
try{
return await axios.get("https://blitz.gg/tft/comps/stats");
}catch(error){
console.error(error);
}
};
var rank = "";
getHtml()
.then(html => {
let ulList = [];
const $ = cheerio.load(html.data);
const $bodyList = $("div.Comps__CompsContainer ol").children("li.notExpanded");
//const $bodyList = $("div.ah_list.PM_CL_realtimeKeyword_list_base ul.ah_l").children("li.ah_item");
//log($bodyList);
$bodyList.each(function(i,elem) {
//console.log($(this));
rank += $(this).find("div.CompCard__CardLeft div.TierIconTooltip__TierIconBox svg.createSvgIcon__Svg title").text() + "\n";
rank += $(this).find("h1.typography__Body2").text() + '\n';
// ulList[i] = {
// //title: $(this).find('span.ah_k').text(),
// //url: $(this).find('a.ah_a').attr('href')
// title: $(this).find('td.info a.title').text().trim()
// };
// console.log(ulList[i].title);
});
log(rank);
});
exports.compositionFunction = function(req,res){
const responseBody = {
"version": "2.0",
"template": {
"outputs": [
{
"simpleText": {
"text": rank
}
}
]
}
}
res.status(200).send(responseBody);
}