【发布时间】:2022-01-05 22:47:04
【问题描述】:
我的 JSON 看起来像这样(但有很多这样的行):
{"text": "Home - Homepage des Kunstvereins Pro Ars Lausitz e.V.\nKunst. Und so weiter.", "timestamp": "2018-01-20T18:56:35Z", "url": "http://proarslausitz.de/1.html"}
{"text": "Bildnummer: 79800031\nVektorgrafikSkalieren Sie ohne Aufl\u00f6sungsverlust auf jede beliebige. Ende.", "url": "http://www.shutterstock.com/de/pic.mhtml?id=79800031&src=lznayUu4-IHg9bkDAflIhg-1-15"}
我想创建一个 .txt 文件,其中仅包含来自 text 的文本。所以它只是:
Home - Homepage des Kunstvereins Pro Ars Lausitz e.V.\nKunst. Und so weiter. Bildnummer: 79800031\nVektorgrafikSkalieren Sie ohne Aufl\u00f6sungsverlust auf jede beliebige. Ende.
没有字符串,什么都没有。我认为编码(因为元音变音)之后不难解决。但是关于文本提取,我知道我可以做到:
json_object = json.loads(json_object_string)
print(json_object["text"])
但这只是为了一条线。我需要遍历这些行吗?如何将文本合并到一个 .txt 文件中?
【问题讨论】:
-
只遍历行