나는 오랫동안 파이썬을 사용하지 않았고 ESPN의 판타지 축구 웹 사이트에서 일부 정보를 긁어 내기 위해 웹 사이트를 따르려고 노력하고 있습니다. 내가 사용하는 wesbite는 https://stmorse.github.io/journal/espn-fantasy-v3.html 입니다. 아래에 나열된 코드를 시도하면 KeyError : 'schedule'이 발생합니다.
웹 사이트의 코드를 정확하게 따라 시도했지만 동일한 오류가 발생합니다. https://fantasy.espn.com/apis/v3/games/ffl/seasons/2019/segments/0/leagues/14380834?view=mMatchup 에서 API를 열었고 일정을위한 장소가 있는지 확인했습니다. 내가해야 할 일이 있는지 확인하십시오.
league_id = 14380834
year = 2019
url = "https://fantasy.espn.com/apis/v3/games/ffl/seasons/2019/segments/0/leagues/14380834/"
r = requests.get(url)
d = r.json()
r = requests.get(url, params={"view": "mMatchup"})
df = [[
game['matchupPeriodId'],
game['home']['teamId'], game['home']['totalPoints'],
game['away']['teamId'], game['away']['totalPoints']
] for game in d['schedule']]
df = pd.DataFrame(df, columns=['Week', 'Team1', 'Score1', 'Team2', 'Score2'])
df['Type'] = ['Regular' if w<=14 else 'Playoff' for w in df['Week']]
df.head()
내 예상 결과는 espn 사이트를 통해 채워진 score2에 대해 일주일 동안 호출하는 5 개의 열입니다.
역 추적은 다음과 같습니다.
File "C:/Users/jacob/PycharmProjects/FF_stuff/app.py", line 15, in <module>
] for game in d['schedule']]
KeyError: 'schedule'
Process finished with exit code 1
d
첫 번째 요청이 아니라 매개 변수를 포함하는 요청 에서 json 을 가져와야 합니다.
이것은 작동합니다
r = requests.get(url, params={"view": "mMatchup"})
d = r.json()
df = [[
game['matchupPeriodId'],
game['home']['teamId'], game['home']['totalPoints'],
game['away']['teamId'], game['away']['totalPoints']
] for game in d['schedule']]
df = pd.DataFrame(df, columns=['Week', 'Team1', 'Score1', 'Team2', 'Score2'])
df['Type'] = ['Regular' if w<=14 else 'Playoff' for w in df['Week']]
df.head()
KeyError
매개 변수가없는 요청에 'schedule'
정보 가 없기 때문에이 ( 가)오고 있었습니다. 당신은 할 수있는 d.keys()
A는 어떤 키를 볼 수 dict
있습니다을
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다