json - 有没有办法从 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: [embedCode] 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 的文件
推荐阅读
- android - Android - NestedScrollView 不滚动
- ruby-on-rails - 更新对象时将对象 ID 传递给 Rails 邮件程序视图
- string - Android:将 URI 从一个活动发送到另一个活动,然后在 ImageView 中显示
- haskell - 类型类实例内的类型类约束
- javascript - 如何使用 Javascript Underscore.js 的 _.sortBy() 方法通过 javascript 中的多个键对对象数组进行排序?
- python - 将两列熊猫数据框合并为一个字符串
- python - 按索引分配多个返回值会影响 Python 中的性能吗?
- docker - 从 docker 运行 gradle:无法从 maven 存储库获取工件
- autodesk-forge - 欧特克锻造;无需新上传即可务实地更改文件位置
- ios - Application.OpenUrl(''file://...") 不适用于 Unity 的 iOS 构建