因此,为了教育目的,我试图抓住此页面上的表格:https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016
我的打印回复
<Response [200]>
这意味着它很好,对吧?但是当我将response.json()放入变量并尝试将其打印出来时,我得到了#ValueError:没有JSON对象可以被解码&#39;
这是我的代码:
import requests
headers = {
'accept-encoding': 'gzip, deflate, sdch, br',
'x-requested-with': 'XMLHttpRequest',
'accept-language': 'nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4',
'user-agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'accept': 'application/json, text/javascript, */*; q=0.01',
'referer': 'https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016',
'model-last-mode': 'GgVBlUgZgMvkAZA4DkgCYAYJauGyQ5BQAQW5ZLGd5qk=',
'authority': 'www.whoscored.com',
'cookie': 'visid_incap_774904=E5yi1BIhTqKa7QY7CTHvbCgWQlcAAAAAQUIPAAAAAAAbmGcCJZ/yA5tiB2vsu1g6; crtg_rta=cc970250d%3Bcc300600d%3Bhw970250d%3B; incap_ses_128_774904=GEttC+rfv2wXecdRg7/GAUAaeVcAAAAA5ZSbfyTF02TorJxEKZxkUg==; _gat=1; _ga=GA1.2.1512369618.1463948865',
}
params = {
'category': 'shots',
'subcategory': 'zones',
'statsAccumulationType': '0',
'field': '',
'tournamentOptions': '',
'timeOfTheGameStart': '0',
'timeOfTheGameEnd': '5',
'teamIds': '',
'stageId': '12496',
'sortBy': 'Rating',
'sortAscending': '',
'page': '1',
'numberOfTeamsToPick': '',
'isCurrent': 'true',
'formation': ''
}
response = requests.get('https://www.whoscored.com/StatisticsFeed/1/GetTeamStatistics?category=shots&subcategory=zones&statsAccumulationType=0&field=&tournamentOptions=&timeOfTheGameStart=0&timeOfTheGameEnd=5&teamIds=&stageId=12496&sortBy=Rating&sortAscending=&page=1&numberOfTeamsToPick=&isCurrent=true&formation=', headers=headers, params=params)
data = response.json()
print data
答案 0 :(得分:1)
您正在打印对象,需要调用text
属性。响应对象没有json属性。
result = requests.get(url)
print result.text
如果你想获得一个json结果,你需要解析一个字符串的结果并将其转换为dict,然后使用json.dumps
将其转换为json