An unofficial espn "api" attempt for Node.js that gets data by scraping the espn ff page. Its not really usable at this point especially since the ESPN fantasy football website is always changing. Feel free to use any of the code in this if you are attempting to make your own web scraper for ESPN.
npm i espn-api
const espn_api = require("espn-api");
const espnApi = require("espn-api").espnApi;
const api = new espnApi("username", "password", "462787");
(async()=>{
await api.login();
const standing = await api.getStandings();
const scores = await api.getScores();
await api.closeBrowser();
})()
login() will login to espn leagues using the username and password that is passed in when the espn_api is initialized. Might be needed when getting private league data.
getStandings() returns a Promise of an object of the format:
{
standings_list:
[ 'rank team_name',
'rank team_name',
'rank team_name',
...],
standings_map:
Map {
rank => [ strings in the same format above of all the teams of rank],
rank => [ strings in the same format above of all the teams of rank],
...}
}
getScores() will return a Promise of an object of the format:
{ scoresAsList:
[ [ 'team_name', 'score' ],
[ 'team_name ', 'score' ],
[ 'team_name', 'score' ],
...],
scoreboards:
{ '0': { home: ['team_name', 'score'], away: ['team_name', 'score'] },
'1': { home: ['team_name', 'score'], away: ['team_name', 'score'] },
'2': {home: ['team_name', 'score'], away: ['team_name', 'score'] },
...}
}
Closes the browser instance.