UNPKG

gametracker-scraper

Version:

A module that allows you to scraping from Gametracker

43 lines (37 loc) 1.15 kB
const axios = require('axios'), cheerio = require('cheerio'); module.exports = { get: async function(url) { const every_nth = (oyuncular, nth) => oyuncular.filter((e, i) => i % 4 === nth - 1); const response = await axios.get(url); const $ = cheerio.load(response.data); let arr = [] let map = $('div#HTML_curr_map').text().replace(/\s/g, '') let online = $('#HTML_num_players').text().replace(/\s/g, '') let maks = $('#HTML_max_players').text().replace(/\s/g, '') let oyuncular = $('div#HTML_online_players table.table_lst.table_lst_stp td').text().replace(/\t/gi, " ").replace(/\n/gi, " ").split(" ") oyuncular.forEach(x => { if (x == '') return; x.replace(/ /gi, ""); if (x == ' ') return; if (x == " Name") x = "Name"; if (x == " Score") x = "Score"; if (x == " Time Played") x = "Time Played"; arr.push(String(x)); }) let plyrs = every_nth(arr, 2); let scores = every_nth(arr, 3); let times = every_nth(arr, 4); let objs = { Map: map, Online: online, Maxs: maks, Players: { 'Name': plyrs.map(player => player), 'Score': scores.map(score => score), 'Times': times.map(times => times) } } return objs } }