TrevorBliss
TrevorBliss

Reputation: 391

How to get athleteId from first/last name using ESPN APIs?

Using ESPN's developer API's, you can query for news on a specific athlete using the 'athleteId'. See the Methods section of their docs:

http://developer.espn.com/docs/headlines#parameters

If you look up a player profile you can find the athlete id in the url of the page, but my question is how can we find this id using solely the APIs? With just the athlete's name?

Upvotes: 2

Views: 1898

Answers (3)

MShack
MShack

Reputation: 652

All NFL player ID can be found on this page

https://sports.core.api.espn.com/v3/sports/football/nfl/athletes?limit=18000

This will return all NFL players ID , name and DOB

function GetESPNIds() {
    var url = 'https://sports.core.api.espn.com/v3/sports/football/nfl/athletes?limit=20000';
    $.ajax({
        type: "GET",
            url: url,
            success: function (data) {
            for (var i=0;i<data.items.length;i++) {
                if(data.items[i].hasOwnProperty("lastName") && data.items[i].hasOwnProperty("firstName") && data.items[i].hasOwnProperty("dateOfBirth")) {
                    console.log("Name: "+data.items[i].lastName+","+data.items[i].firstName +" ID: " +data.items[i].id +" DOB: " +data.items[i].dateOfBirth);
                }
            }
            }
    });
}

GetESPNIds();

Upvotes: 0

chitown88
chitown88

Reputation: 28630

As stated, it's all available in the api:

import requests
import pandas as pd

url = 'https://sports.core.api.espn.com/v3/sports/football/nfl/athletes?limit=18000'
jsonData = requests.get(url).json()

players = pd.DataFrame(jsonData['items']).dropna(subset='firstName')
players = players[['id', 'fullName']].dropna()

Output:

print(players)
            id          fullName
6        14856     Isaako Aaitui
7      3058033        Manny Abad
8        16836  Jared Abbrederis
9      2576467    Mehdi Abdesmad
10       14466  Isa Abdul-Quddus
       ...               ...
16920    16424     Mike Zupancic
16921    15462   Markus Zusevics
16922    11317     Jeremy Zuttah
16923  4294520   Brandon Zylstra
16924  4608362     Shane Zylstra

[16919 rows x 2 columns]

Upvotes: 2

fafafooey
fafafooey

Reputation: 181

If you go to a team's roster page, use inspect element, or whatever equivalent for the browser you use, and look at the table element of all the players on the team. Within the 'td' tags, you'll find a player ID. You could scrape the screen, store all of the player ids locally, and then use them as parameters in your api calls. This is merely a suggestion, but it should work, if the id that is used on the page is the same as the id needed to get that player's information in api.

Upvotes: 1

Related Questions