forked from damilolaolatunji/scraper-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpl-scraper.js
30 lines (24 loc) · 851 Bytes
/
pl-scraper.js
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
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.premierleague.com/stats/top/players/goals?se=-1&cl=-1&iso=-1&po=-1?se=-1';
axios(url)
.then(response => {
const html = response.data;
const $ = cheerio.load(html)
const statsTable = $('.statsTableContainer > tr');
const topPremierLeagueScorers = [];
statsTable.each(function () {
const rank = $(this).find('.rank > strong').text();
const playerName = $(this).find('.playerName > strong').text();
const nationality = $(this).find('.playerCountry').text();
const goals = $(this).find('.mainStat').text();
topPremierLeagueScorers.push({
rank,
name: playerName,
nationality,
goals,
});
});
console.log(topPremierLeagueScorers);
})
.catch(console.error);