API-FOOTBALL

부분 유료
Verified
분류별 API-SPORTS | 업데이트됨 11日前 | Sports
인기

10 / 10

지연 시간

366ms

서비스 수준

100%

Health Check

N/A

모든 토론으로 돌아가기

Only returning 20 players from specific league?

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 2年前

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 2年前

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 2年前

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

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입