iimadouu
New Coder
hello, im trying to filter and organize a Json response from axios.get, im requesting a soccer standings table i ve succeded in returning the data but is bit messy,
im using node
express,
axios,
and cheerio as you can see on my code below
this is my code:
and this is how the response looks like :
what i want is how do i remove these " /n /n /n …" that are showing up and the second thing is i want to make the result like this:
Thank you!
im using node
express,
axios,
and cheerio as you can see on my code below
this is my code:
JavaScript:
const express = require('express');
const PORT = 8888
const app = express();
const cheerio = require('cheerio');
const axios = require("axios");
app.get('/td', async (req, res) => {
var results = [];
try {
const url = "https://www.footmercato.net/algerie/ligue-1/classement";
const { data } = await axios.get(url);
const $ = cheerio.load(data);
$("body > div.container.container--flex.container--column > div.content > section > div.classement.classement--longMode > table > tbody").each((index, element) => {
var team = $(element).find("td.classement__team").text();
var rank = $(element).find("td.classement__rank").text();
var points = $(element).find("td.classement__highlight").text();
results.push({team: team.trim(),
rank: rank.trim(),
points: points.trim(),
});
});
} catch (err) {
console.error(err);
}
res.json({
"message":"success",
"data": results
})
});
app.listen(PORT, () => console.log(`surver running on PORT ${PORT}`))
and this is how the response looks like :
JSON:
{"message":"success","data":[{"team":"Belouizdad\n \n \n \n CS Constantine\n \n \n \n Saoura\n \n \n \n MC Alger\n \n \n \n ES Sétif\n \n \n \n Khenchela\n \n \n \n USM Alger\n \n \n \n RC Arbaâ\n \n \n \n ASO Chlef\n \n \n \n US Biskra\n \n \n \n NC Magra\n \n \n \n MC Oran\n \n \n \n Bayadh\n \n \n \n Kabylie\n \n \n \n Paradou\n \n \n \n HBCL","rank":"1\n \n 2\n \n 3\n \n 4\n \n 5\n \n 6\n \n 7\n \n 8\n \n 9\n \n 10\n \n 11\n \n 12\n \n 13\n \n 14\n \n 15\n \n 16","points":"3029232222201918171717161612121"}]}
what i want is how do i remove these " /n /n /n …" that are showing up and the second thing is i want to make the result like this:
JSON:
"team": "Belouizdad"
"rank": "1"
"points: "30"
"team": "CS Constatine"
"rank": "2"
"points":"29"
..... etc
Thank you!