如何使用python从JSON输出中获得唯一匹配的结果?

2024-09-30 20:35:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用selenium python编写了一个脚本,我正处于一个需要对http://localhost:0000/v1/s3status进行get调用的位置,并且输出将如所附的图片所示。Attached output of get call

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

我正在寻找一个只需要特定值的脚本输出的解决方案,stages:{},validated:{},failed:{}

所以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}

Tags: ofthe脚本localhosthttpgetseleniumbe
1条回答
网友
1楼 · 发布于 2024-09-30 20:35:22

首先,您需要将请求转换为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']))

相关问题 更多 >