Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python和Json—从API输出打印出键/值并对其进行结构化_Python_Json_Api_Key Value - Fatal编程技术网

Python和Json—从API输出打印出键/值并对其进行结构化

Python和Json—从API输出打印出键/值并对其进行结构化,python,json,api,key-value,Python,Json,Api,Key Value,输入: 我设法通过数据中的键将其分解: 输出: data = {'data': {'requests': [], 'cookies': [], 'console': [], 'links': [], 'timing': {'beginNavigation': '2020-10-13T13:29:48.999Z', 'frameStartedLoading': '2020-10-13T13:29:49.889Z', 'frameNavigated': '2020-10-13T13:29:49.89

输入:

我设法通过数据中的键将其分解:

输出:

data = {'data': {'requests': [], 'cookies': [], 'console': [], 'links': [], 'timing': {'beginNavigation': '2020-10-13T13:29:48.999Z', 'frameStartedLoading': '2020-10-13T13:29:49.889Z', 'frameNavigated': '2020-10-13T13:29:49.899Z', 'loadEventFired': '2020-10-13T13:29:49.899Z', 'frameStoppedLoading': '2020-10-13T13:29:49.899Z', 'domContentEventFired': '2020-10-13T13:29:49.899Z'}, 'globals': []}, 'stats': {'resourceStats': [], 'protocolStats': [], 'tlsStats': [], 'serverStats': [], 'domainStats': [], 'regDomainStats': [], 'ipStats': []}, 'meta': {'processors': {'geoip': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'geoip': {'range': [2717966336, 2717970431], 'country': 'CA', 'region': '', 'eu': '0', 'timezone': 'America/Toronto', 'city': '', 'll': [43.6319, -79.3716], 'metro': 0, 'area': 1000, 'country_name': 'Canada'}}]}, 'asn': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'asn': '22612', 'country': 'US', 'registrar': 'arin', 'date': '2011-06-21', 'description': 'NAMECHEAP-NET, US', 'route': '162.0.232.0/24'}]}, 'rdns': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'ptr': 'server290-1.web-hosting.com'}]}, 'wappa': {'state': 'done', 'data': []}, 'done': {'state': 'done', 'data': {'state': 'done'}}}}, 'task': {'uuid': '4f830f9c-57e3-4099-9840-44fa8e1f5f7c', 'time': '2020-10-13T13:29:48.871Z', 'url': 'http://billinginfo-netflix.com/', 'visibility': 'public', 'options': {'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}, 'method': 'api', 'source': 'c49ff09d', 'tags': [], 'reportURL': 'https://urlscan.io/result/4f830f9c-57e3-4099-9840-44fa8e1f5f7c/', 'screenshotURL': 'https://urlscan.io/screenshots/4f830f9c-57e3-4099-9840-44fa8e1f5f7c.png', 'domURL': 'https://urlscan.io/dom/4f830f9c-57e3-4099-9840-44fa8e1f5f7c/'}, 'page': {}, 'lists': {'ips': [], 'countries': [], 'asns': [], 'domains': [], 'servers': [], 'urls': [], 'hashes': []}, 'verdicts': {'overall': {'score': 0, 'categories': [], 'brands': [], 'tags': [], 'malicious': False, 'hasVerdicts': 0}, 'urlscan': {'score': 0, 'categories': [], 'brands': [], 'tags': [], 'detectionDetails': [], 'malicious': False}, 'engines': {'score': 0, 'malicious': [], 'benign': [], 'maliciousTotal': 0, 'benignTotal': 0, 'verdicts': [], 'enginesTotal': 0}, 'community': {'score': 0, 'votes': [], 'votesTotal': 0, 'votesMalicious': 0, 'votesBenign': 0, 'tags': [], 'categories': []}}}

for key, value in data.items():
    print(f"{key} = {value}")

如何从verdict中获取这些子值并打印如下内容:

data = {'requests': [], 'cookies': [], 'console': [], 'links': [], 'timing': {'beginNavigation': '2020-10-13T13:29:48.999Z', 'frameStartedLoading': '2020-10-13T13:29:49.889Z', 'frameNavigated': '2020-10-13T13:29:49.899Z', 'loadEventFired': '2020-10-13T13:29:49.899Z', 'frameStoppedLoading': '2020-10-13T13:29:49.899Z', 'domContentEventFired': '2020-10-13T13:29:49.899Z'}, 'globals': []}
stats = {'resourceStats': [], 'protocolStats': [], 'tlsStats': [], 'serverStats': [], 'domainStats': [], 'regDomainStats': [], 'ipStats': []}
meta = {'processors': {'geoip': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'geoip': {'range': [2717966336, 2717970431], 'country': 'CA', 'region': '', 'eu': '0', 'timezone': 'America/Toronto', 'city': '', 'll': [43.6319, -79.3716], 'metro': 0, 'area': 1000, 'country_name': 'Canada'}}]}, 'asn': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'asn': '22612', 'country': 'US', 'registrar': 'arin', 'date': '2011-06-21', 'description': 'NAMECHEAP-NET, US', 'route': '162.0.232.0/24'}]}, 'rdns': {'state': 'done', 'data': [{'ip': '162.0.232.249', 'ptr': 'server290-1.web-hosting.com'}]}, 'wappa': {'state': 'done', 'data': []}, 'done': {'state': 'done', 'data': {'state': 'done'}}}}
task = {'uuid': '4f830f9c-57e3-4099-9840-44fa8e1f5f7c', 'time': '2020-10-13T13:29:48.871Z', 'url': 'http://billinginfo-netflix.com/', 'visibility': 'public', 'options': {'useragent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}, 'method': 'api', 'source': 'c49ff09d', 'tags': [], 'reportURL': 'https://urlscan.io/result/4f830f9c-57e3-4099-9840-44fa8e1f5f7c/', 'screenshotURL': 'https://urlscan.io/screenshots/4f830f9c-57e3-4099-9840-44fa8e1f5f7c.png', 'domURL': 'https://urlscan.io/dom/4f830f9c-57e3-4099-9840-44fa8e1f5f7c/'}
page = {}
lists = {'ips': [], 'countries': [], 'asns': [], 'domains': [], 'servers': [], 'urls': [], 'hashes': []}
verdicts = {'overall': {'score': 0, 'categories': [], 'brands': [], 'tags': [], 'malicious': False, 'hasVerdicts': 0}, 'urlscan': {'score': 0, 'categories': [], 'brands': [], 'tags': [], 'detectionDetails': [], 'malicious': False}, 'engines': {'score': 0, 'malicious': [], 'benign': [], 'maliciousTotal': 0, 'benignTotal': 0, 'verdicts': [], 'enginesTotal': 0}, 'community': {'score': 0, 'votes': [], 'votesTotal': 0, 'votesMalicious': 0, 'votesBenign': 0, 'tags': [], 'categories': []}}


为了去除大量不必要的数据,我一直在努力,终于找到了答案。我只是想把事情复杂化

Overall:
Score: 0
Malicious: false

我看不出你的问题,我想你需要一些字典的一般帮助()。输出中的元素也是字典。您可以访问诸如
verdicsts[“总体”][“分数”]
之类的元素,也可以不使用输出
data[“总体”][“分数”]
data['verdicts']['overall']['malicious']