API-FOOTBALL

ÜCRETSİZ PREMIUM
Verified
Taraf API-SPORTS | Güncelleyen il y a 8 jours | Sports
Popülerlik

10 / 10

Gecikme

364ms

Hizmet Düzeyi

99%

Health Check

N/A

Tüm Tartışmalara Dön

Only returning 20 players from specific league?

Rapid account: Ckelleher Bektqav Qm
ckelleher-BektqavQm
il y a 2 ans

Hello - I’m trying to pull player data for a specific league into a pandas DataFrame, but when I run my application, it’s only returning 20 results. Do I need to pass additional parameters to get all players? Is the free version of the API limiting the # of players? Or is it some other issue with what I’m doing?

My code is below:

import requests
import pandas as pd
import json
from dash import Dash, dcc, html, dash_table
import dash_bootstrap_components as dbc
from dash.dash_table.Format import Format, Padding

url = "https://api-football-v1.p.rapidapi.com/v3/players"

querystring = {"league":"39","season":"2020"}

headers = {
	"X-RapidAPI-Host": "api-football-v1.p.rapidapi.com",
	"X-RapidAPI-Key": "xxxxxxx"
}

response = requests.request("GET", url, headers=headers, params=querystring)

comment Check keys of ‘response’

response.json().keys()

commentCheck keys at next level of ‘response’

response.json().keys()

comment Create dictionary of results for ‘players’ key

players_dict = response.json()

comment Create a dataframe from the dictionary

players_df = pd.DataFrame.from_dict(players_dict, orient='index')
Rapid account: Api Sports
api-sports Commented il y a 2 ans

You have to call each page in a loop, there is too much data to receive all data in one call.

Best

Rapid account: Ckelleher Bektqav Qm
ckelleher-BektqavQm Commented il y a 2 ans

Ok - that’s very helpful, thank you!

For the ‘page’ parameter, is there a way include ‘all’ pages? Or would I have to pass it through a loop to collect every page?

Rapid account: Api Sports
api-sports Commented il y a 2 ans

Hi,

This endpoint is paginated with 20 results per page as indicated in the documentation. So you have to add the parameter “page” to see the next results.

As example :

{
get: "players"
parameters: {
league: "39"
season: “2020”
}
errors: [
]
results: 20
paging: {
current: 1
total: 37
}

There is 37 pages for this league id and season.

Best

Aşağıya yorum ekleyerek tartışmaya katılın:

Yeni yorumlar göndermek için giriş yapın / kaydolun