2017-08-30 148 views
0

我想凑这个链接的网站:获取JSON数据与Python

https://www.whoscored.com/Players/11119/Show/Lionel-Messi

我想从汇总的数据,防守,进攻的标签和我试图 这:

import requests 
# This is the json data link i wish to get from the defensive tab (from developer tools) 
url = "https://www.whoscored.com/StatisticsFeed/1/GetPlayerStatistics?category=summary&subcategory=defensive&statsAccumulationType=0&isCurrent=true&playerId=11119&teamIds=&matchId=&stageId=&tournamentOptions=&sortBy=Rating&sortAscending=&age=&ageComparisonType=&appearances=&appearancesComparisonType=&field=Overall&nationality=&positionOptions=&timeOfTheGameEnd=&timeOfTheGameStart=&isMinApp=false&page=&includeZeroValues=true&numberOfPlayersToPick=" 

response = requests.get(url) 

print(response.json()) 

我无法管理打印JSON数据并从标签中刮取需要的数据,我是否做错了什么? 感谢您的帮助。

+0

URL至少与此问题中所写的一样无效。 – n1c9

+0

响应是HTML,而不是JSON,所以这不起作用。 – Kamran

回答

0

当按照规定执行代码时,响应会返回403状态“禁止”。

也许这个提供者不希望他们的数据被抓取并且检查请求是否有非浏览器访问的迹象,并且返回这个错误。

继续操作前请务必检查您的response.status_code

+0

地位确实是403,反正我还可以报废数据吗? –

+0

你有没有尝试添加一个头像基本的东西,如用户代理? – jlaur

+0

也许cookie处理使用requests.Session()... – jlaur