2 回答

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊
如果您只想將“文本”字段保存在 json 文件中,您可以調(diào)整該TwitterListener.on_data方法的定義:
import json
def on_data(self, data):
try:
print(data)
with open(self.fetched_tweets_filename, 'a') as tf:
json_load = json.loads(data)
text = {'text': json_load['text']}
tf.write(json.dumps(text))
return True
except BaseException as e:
print("Error on_data %s" % str(e))
return True
公平警告,我沒有tweepy安裝/設(shè)置,所以我只能使用您在上面發(fā)布的 json 文件測(cè)試上述代碼的一個(gè)版本。如果您遇到任何錯(cuò)誤,請(qǐng)告訴我,我會(huì)看看我能做些什么。
添加回答
舉報(bào)