有没有办法从 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 数据创建一个传感器。

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

  • 平台:休息 姓名: covid_19_folkhalsomyndigheten 资源: https://www.arcgis.com/sharing/rest/content/items/2dc63e26f509468f896ec69476b0dab3/data value_template: "{% if value_json.embedCode == '' %} Otillgänglig {% else %} Tillgänglig {% endif %}" json_attributes_path: $.widgets.widget_1.config json_attributes: [嵌入式代码] scan_interval: 21600

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

如果有人有空闲时间指导我完成这项工作,我会非常高兴。谢谢!

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

相关内容

最新更新