我似乎无法获得单个项目,即仅获得文本或仅获得用户。
我尝试将其用作字典或列表,但似乎无济于事。但是,我不知道我是一名业余爱好者时,我的测试有多可靠。
def on_data(self, data):
try:
print(data.text(?))
with open(self.fetched_tweets_filename, 'a') as tf:
tf.write(data)
return True
except BaseException as e:
print("Error on_data %s" % str(e))
return True
我想要“样本推文”,但是我遇到各种各样无法解析的错误
答案 0 :(得分:0)
StreamListener的on_data
方法将原始数据作为字符串接收。
您可以使用json.loads
将JSON反序列化为字典以访问“文本”键。
参见https://github.com/tweepy/tweepy/blob/29bae1fde3ae0636fa13e5ed69f68f2af75c110b/tweepy/streaming.py#L42-L48。
或者,您可以使用on_status
来获取具有text
属性的Status对象。