我想知道如何使用 python 从网站中提取实时数据。这是网站的链接:https : //live.alphatiming.co.uk/24hr
从我在网络中看到的内容来看,该页面对以下 URL 进行了 GET 调用:https : //live.alphatiming.co.uk/24hr.json以获取数据。
在这种情况下,最简单的方法是使用requests
来重现并解析 json:
import requests
response = requests.get(url='https://live.alphatiming.co.uk/24hr.json').json()
print(response) # This will print out the data coming from that endpoint
要获得您正在寻找的数据,只需像使用 dict 一样使用 response 即可。例如:
# print only Competitors data:
print(response['Competitors'])
# print out list with the names of teams:
print([competitor['CompetitorName'] for competitor in response['Competitors']])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句