有没有一种方法可以从rest api请求特定的数据集?

时间:2020-06-26 17:29:00

标签: json yaml

对不起,如果这对您中的某些人来说似乎很愚蠢,我是一个完全的菜鸟,从字面上不知道我要尝试使用什么Google,因此我什至无法在询问之前尝试使用谷歌搜索。

我想从此页面上专门提取英国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属性(如果可能)。

我正在尝试使用其余平台在Home Assistant中为英格兰Covid19数据创建一个传感器。

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

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

如果有人有空闲时间来指导我,我将非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

在这里,这是使用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的文件