【发布时间】:2021-02-12 01:46:19
【问题描述】:
对不起,如果我的措辞有误。我没有接受过 python 培训。
我请求了一个 JSON,并且可以手动提取我想要的数据。我知道有更好的方法来请求我想要的数据并且希望指向正确的方向。
这是我所拥有的(我只包含了 JSON 的一部分):
> This is the example of the JSON that I am requesting.
{"games": {
>
> "0":{
> "id":"371749","gameUID":"1213028","sport":"Football","league":"NCAA","sportsbook":"BetOnline","startDate":"2020-10-29T23:30:01Z","awayRotationNumber":"103","homeRotationNumber":"104","awayTeam":"South
> Alabama","homeTeam":"Georgia Southern","description":"South Alabama vs
> Georgia
> Southern","isLive":"0","gameMoneylineAwayPrice":"+165","gameMoneylineHomePrice":"-190","gameSpreadAwayHandicap":"+4","gameSpreadHomeHandicap":"-4","gameSpreadAwayPrice":"-110","gameSpreadHomePrice":"-110","gameTotalPoints":"52","gameTotalOverPrice":"-110","gameTotalUnderPrice":"-110","gameTeamTotalAwayPoints":"24","gameTeamTotalAwayOverPrice":"-110","gameTeamTotalAwayUnderPrice":"-120","gameTeamTotalHomePoints":"28","gameTeamTotalHomeOverPrice":"-115","gameTeamTotalHomeUnderPrice":"-115","halfMoneylineAwayPrice":"+140","halfMoneylineHomePrice":"-160","halfSpreadAwayHandicap":"+3","halfSpreadHomeHandicap":"-3","halfSpreadAwayPrice":"-115","halfSpreadHomePrice":"-105","halfTotalPoints":"26","halfTotalOverPrice":"-115","halfTotalUnderPrice":"-105","periodMoneylineAwayPrice":"+135","periodMoneylineHomePrice":"-155","periodSpreadAwayHandicap":"+0.5","periodSpreadHomeHandicap":"-0.5","periodSpreadAwayPrice":"-105","periodSpreadHomePrice":"-115","periodTotalPoints":"10","periodTotalOverPrice":"-135","periodTotalUnderPrice":"+115","changedDate":"2020-10-29T14:31:16Z","checkedDate":"2020-10-29T15:13:33Z"}
> ,"1":{(same as 0 etc etc...}
res = requests.get("myurl")
data = res.json()
game_one = data['games']['0']['awayTeam'] + " vs " + data['games']['0']['homeTeam'] + " " + data['games']['0']['gameSpreadHomeHandicap'] + " "
game_two = data['games']['1']['awayTeam'] + " vs " + data['games']['1']['homeTeam'] + " " + data['games']['1']['gameSpreadHomeHandicap'] + " "
game_three = data['games']['2']['awayTeam'] + " vs " + data['games']['2']['homeTeam'] + " " +
ticker = game_one + game_two + game_three + game_four
output = open(r'E:\output.txt', 'w')
output.write(ticker)
output.close()
任何帮助将不胜感激。谢谢。
【问题讨论】:
标签: python json distinct-values