请帮我过滤该值。我尝试使用 re 但没有帮助。谢谢!
{"total_count":1,"entries":[{"type":"file","id":"51371323013","file_version":{"type":"file_version","id":"52926277625","sha1":"22596363b3de40b06f981fb85d82312e8c0ed511"},"sequence_id":"1","etag":"1","sha1":"22596363b3de40b06f981fb85d82312e8c0ed511","name":"hello.txt","description":"","size":12,"path_collection":{"total_count":1,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"}]},"created_at":"2016-01-28T23:02:21-08:00","modified_at":"2016-01-28T23:02:21-08:00","trashed_at":null,"purged_at":null,"content_created_at":"2016-01-28T23:01:42-08:00","content_modified_at":"2016-01-28T23:01:42-08:00","created_by":{"type":"user","id":"262253433","name":"RZF-ICA","login":"blah@blah.com"},"modified_by":{"type":"user","id":"262253433","name":"RZF-ICA","login":"blah@blah.com"},"owned_by":{"type":"user","id":"262253433","name":"RZF-ICA","login":"blah@blah.com"},"shared_link":{"url":"https:\/\/app.box.com\/s\/84wqj8mvwm77ern12121mbe4b68lgf","download_url":"https:\/\/app.box.com\/shared\/static\/84wqj8mvwm77ernjtkvm131b68lgf.txt","vanity_url":null,"effective_access":"company","is_password_enabled":false,"unshared_at":null,"download_count":0,"preview_count":0,"access":"company","permissions":{"can_download":true,"can_preview":true}},"parent":{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},"item_status":"active"}],"limit":1,"offset":0}
最佳答案
不要使用正则表达式。使用 json 解析器。它将把 json 解析为嵌套的 python 字典。这比使用正则表达式更加健壮。
import json
data = json.loads(your_input_json_string)
print(data['entries'][0]['shared_link']['download_url'])
如果您使用正则表达式,当您获得包含 "
字符的输入网址时,您可能会遇到错误。这是一个有效的网址:
https://www.google.com/?q="when+not+to+use+regular+expressions"
关于python - 仅从以下输出中过滤 'download_url' 的值 - python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35104686/