composition.js 1.64 KB
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);
}