Skip to content

Commit

Permalink
Update routes.js
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenzY8 authored Dec 19, 2024
1 parent e2a771b commit 1bf744d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,27 @@ router.get("/heroes", async (req, res) => {
const response = await axios.get(url);
const $ = cheerio.load(response.data);
const heroes = [];
$('ul.gallery li.gallerybox').each((i, element) => {
const heroName = $(element).find('div.gallerytext a').attr('title');
const iconUrl = $(element).find('div.thumb img').attr('src');
$('.wikitable tbody tr').each((i, element) => {
const icon = $(element).find('td:nth-child(1) img').attr('data-src');
const heroName = $(element).find('td:nth-child(2)').text().trim();
const heroOrder = $(element).find('td:nth-child(3)').text().trim();
const role = $(element).find('td:nth-child(4) a').map((i, el) => $(el).text()).get().join('/');
const specialty = $(element).find('td:nth-child(5) a').map((i, el) => $(el).text()).get().join('/');
const laneRecommendation = $(element).find('td:nth-child(6) a').text().trim();
const region = $(element).find('td:nth-child(7) a').text().trim();
const price = $(element).find('td:nth-child(8) li').map((i, el) => $(el).text().trim()).get().join(', ');
const releaseDate = $(element).find('td:nth-child(9)').text().trim();
// Push the data into the heroes array
heroes.push({
name: heroName,
icon: 'https://liquipedia.net' + iconUrl
icon,
heroName,
heroOrder,
role,
specialty,
laneRecommendation,
region,
price,
releaseDate,
});
});
res.json(heroes);
Expand Down

0 comments on commit 1bf744d

Please sign in to comment.