如何使用python从实时网站中提取数据?

时间:2018-11-25 17:03:11

标签: python selenium web-scraping beautifulsoup raspberry-pi

我想知道如何使用python从网站中提取实时数据。 这是网站链接:https://live.alphatiming.co.uk/24hr

3 个答案:

答案 0 :(得分:0)

我查看了您在问题中链接的网站,并且很满意看到正轨上的那些点和进度条(不知道为什么)。

但是,我认为requestsbeautifulsoup可以完成工作,只需查看要从何处获取数据的标签即可。

制作用于提取数据的脚本。

然后使用任务计划网站并点击api(您的代码可能托管在heroku上)。

非常直观地了解this。 或您的标签建议使用RasberryPI作为服务器来安排每2-3秒运行一次脚本的任务。

我希望有帮助。

答案 1 :(得分:0)

import requests

s = requests.Session()
url = 'https://live.alphatiming.co.uk/24hr'
page = s.get(url).text

print(page)

答案 2 :(得分:0)

根据我在网络中看到的内容,该页面对此URL https://live.alphatiming.co.uk/24hr.json进行了GET调用,以获取数据。

在这种情况下,最简单的方法是使用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

要获取您想要的数据,只需像字典一样处理响应即可。例如:

# print only Competitors data:
print(response['Competitors'])
# print out list with the names of teams:
print([competitor['CompetitorName'] for competitor in response['Competitors']])