python-3.x - 从 s3 存储桶元文件中提取值
问题描述
我使用从 S3 Bucket 读取文件obj.get()['Body'].read()
并返回
b'[{ "version": "v1", "timeDelta": 0.0, "artist": "", "title": "text="Spot Block End" amgTrackId="9876543"", "timestamp": "1586453290376" }]'
我想提取时间戳键的值。
我在我的 s3 存储桶中存储了一些 .meta 文件,我需要检查我的每个 .meta 文件是否有时间戳
解决方案
这不是 json 格式。似乎您需要转义标题键中的 "
"title": "text=\"Spot Block End\" amgTrackId=\"9876543\""
像这样。
也许你可以尝试使用正则表达式来为你做这件事。
编辑:
import json
import re
input = b'[{ "version": "v1", "timeDelta": 0.0, "artist": "", "title": "text="Spot Block End" amgTrackId="9876543"", "timestamp": "1586453290376" }]'
input = input.decode('utf-8')
match = re.findall('(?<=\"title\": \").*\"(?=\")',input)[0]
escaped_match = json.dumps(match)
input = input.replace(match,escaped_match[1:-1])
print(json.loads(input))
看看这段代码,有点难看,但是可以。
希望能帮助到你!
推荐阅读
- domain-driven-design - 在 CQRS 中的域事件处理程序中创建命令
- javascript - Chrome 扩展:内容策略抱怨内联事件处理程序,我找不到它
- node.js - 如何从节点 js 向浏览器发送分块的 gzip 响应
- asp.net-mvc - 如何让 .Net Core Action 返回 Nothing 或 Redirect
- r - R 中执行此字符串正则表达式处理的最快替代方法是什么?
- excel - 简单的 VBA 宏将适用于除一台以外的所有计算机
- html - Chrome 在放大时不会保持一致的 rem 单位
- r - 如何在某些 R 函数中隐式调用列
- python - 使用可拖动的 QLabel 进行裁剪
- javascript - 如何将 Tablesorter 与列选择器小部件一起使用 - 错误?