如何获得只使用Python从JSON输出匹配的结果呢?

问题描述 投票:-3回答:1

我已经写在硒的Python脚本,我被困在一个地步,我想打一个获得来电http://localhost:0000/v1/s3status,输出会像在图像显示attached.Attached output of get call

datasources= requests.get("http://localhost:0000/v1/s3status")

我要寻找一个解决方案,我只需要脚本输出仅针对特定值,阶段:{},验证:{}失败:{}

所以Python脚本的输出应该是这样的:

Datasources of Staged :{Whatever the result will be inside}
Datasources of Failed :{Whatever the result will be inside} 
Datasouces of Validated :{Whatever the result will be inside}
python selenium scripting output
1个回答
0
投票

首先,你需要将你的请求转换成JSON。

import json
import requests

datasources= requests.get("http://localhost:0000/v1/s3status").json()

print("Staged : {}".format(datasources['staged']))
print("Failed : {}".format(datasources['failed']))
print("Validated : {}".format(datasources['validated']))
© www.soinside.com 2019 - 2024. All rights reserved.