首页 > 解决方案 > 有没有办法从 rest api 请求特定的数据集?

问题描述

对不起,如果这对你们中的一些人来说似乎很愚蠢,我是一个完全的菜鸟,我根本不知道我在谷歌上要做什么,所以在我问之前我什至不能尝试谷歌搜索。

我想从这个页面专门提取英国covid19数据: https ://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/Coronavirus_2019_nCoV_Cases/FeatureServer/1/query?where=1%3D1&outFields=*&outSR=4326&f= json

然后将其设置为 json 属性(如果可能)。

我正在尝试使用其余平台在英格兰 Covid19 数据的家庭助理中创建一个传感器。

我从已经成功实现这一点的其他人那里得到这个想法:

但是他使用的实际资源和我的资源存在差异,所以也许我不能只是复制他的方法。

如果有人有空闲时间指导我完成这件事,我将非常感激。谢谢!

标签: jsonyaml

解决方案


来吧,这是使用python3的答案

import json
import requests # you'll have to install this with something like pip

r=requests.get('https://services1.arcgis.com/0MSEUqKaxRlEPj5g/arcgis/rest/services/Coronavirus_2019_nCoV_Cases/FeatureServer/1/query?where=1%3D1&outFields=*&outSR=4326&f=json')

print(r.text, ' this will be your json object')

# if you want to write the data to a file called data.txt (note you can choose any name like corona.txt)
with open('data.txt', 'w') as outfile:
    json.dump(r.text, outfile)

以下代码将获取数据,然后编写并创建一个名为 data.txt 的文件


推荐阅读