查看此要点以获取详细信息:https://gist.github.com/stockninja/7b9bcbfc8f338da414ae9678ec98016d
违规脚本被称为main.py
,我包含了一些尝试的输出,用于了解失败的原因。
我完全不知道失败了什么!
答案 0 :(得分:4)
非常简单的解决方案,与代理无关,您需要添加用户代理:
def sync():
head = {"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"}
all_urls = urls()
for url in all_urls:
res = requests.get(url, headers=head)
print(url)
print(res.json())
一旦你这样做:
In [2]: sync()
http://stats.nba.com/stats/teamgamelog?TeamID=1610612737&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612737, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
http://stats.nba.com/stats/teamgamelog?TeamID=1610612738&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612738, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
http://stats.nba.com/stats/teamgamelog?TeamID=1610612751&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612751, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
http://stats.nba.com/stats/teamgamelog?TeamID=1610612766&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612766, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
http://stats.nba.com/stats/teamgamelog?TeamID=1610612741&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612741, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
http://stats.nba.com/stats/teamgamelog?TeamID=1610612739&Season=2016-15&SeasonType=Regular+Season
{'resource': 'teamgamelog', 'parameters': {'TeamID': 1610612739, 'Season': '2016-15', 'LeagueID': None, 'SeasonType': 'Regular Season'}, 'resultSets': [{'name': 'TeamGameLog', 'rowSet': [], 'headers': ['Team_ID', 'Game_ID', 'GAME_DATE', 'MATCHUP', 'WL', 'MIN', 'FGM', 'FGA', 'FG_PCT', 'FG3M', 'FG3A', 'FG3_PCT', 'FTM', 'FTA', 'FT_PCT', 'OREB', 'DREB', 'REB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS']}]}
依此类推....................
如果没有每次获得400,您可能还需要考虑请求之间的睡眠以及调查每天的速率限制/请求。