【发布时间】:2018-06-29 18:38:51
【问题描述】:
我正在尝试在 python 中解析 API 调用的结果。
{'data': [{'type': 'infra_process_running', 'name': 'Custom Plugin Alert - Stopped Running', 'enabled': True, 'filter': {'and': [{'is': {'entityName': 'SOMEHOSTNAME','SOMEHOSTNAME'}}]}, 'id': 123456, 'created_at_epoch_millis': 1513024072143, 'updated_at_epoch_millis': 1513024072176, 'policy_id': 127350, 'comparison': 'below', 'critical_threshold': {'value': 2, 'duration_minutes': 5}, 'process_filter': {'and': [{'is': {'commandLine': 'java'}}]}}], 'meta': {'limit': 50, 'offset': 0, 'total': 1}, 'links': {}}
编辑:抱歉忘了说这是在 python 中对请求运行 print 的输出,这就是为什么它是单引号而不是像 JSON 那样双引号
我想从此请求中提取所有“名称”和所有“实体名称”。 我尝试使用正则表达式搜索并将它们存储在列表中
list.append(re.search(r"', 'name': '(.*?)', '", stringInfJSON))
list.append(re.search(r"{'entityName': ['(.*?)']", stringInfJSON))
我想从此请求中提取所有“名称”和所有“实体名称”。
然后我想以以下格式将所有这些插入到 Excel 电子表格中
+---------------------------------------+---------------------+
| Somehostname(s) | Somehostname2 |
+---------------------------------------+---------------------+
| Custom Plugin Alert - Stopped Running | Blah Blah Blah Blah |
+---------------------------------------+---------------------+
【问题讨论】:
-
到目前为止你有什么尝试?
标签: python json regex csv python-requests