JSON文件的示例: https://nofile.io/f/J3EqSk2CWsB/raw_tweets.json
我试图仅使用full_text提取位,因此输出应如下所示:
#Deathstroke 31 @DCComics \u2022 super airDrop opening & it only gets better from there \u2022 it\u2019s not just
#BatmanMammaMia, folks! #SladeWilson in dept to #Mento & #BruceWayne methodology a bit more cosmopolitan https:\/\/t.co\/jWUGBn4Fqm
我正在使用此代码:
saveFile = open('raw_tweets.json','r')
for line in saveFile:
tweet = line.split(':{"full_text":"')[1].split(',"display_text_range":"')[0]
print(tweet)
我收到了这个错误:
Traceback (most recent call last):
File "c:\Users\shortening_tweets.py", line 7, in <module>
tweet = line.split(':{"full_text":"')[1].split(',"display_text_range":"')[0]
IndexError: list index out of range
第7行是拆分的行 有人能告诉我我做错了什么吗?
答案 0 :(得分:2)
import json
tweet = json.loads(line)['extended_tweet']['full_text']