【发布时间】:2018-10-06 14:58:04
【问题描述】:
我正在使用 tweepy Streaming api 从 twitter 流式传输数据,
class MyStreamListener(tweepy.StreamListener):
def __init__(self):
super().__init__()
self.counter = 0
self.limit = 8
self.q=list()
def on_status(self, status):
self.counter += 1
if self.counter < self.limit:
self.q.append(status.user.name)
self.q.append(status.user.statuses_count)
#print(status.text)
else:
myStream.disconnect()
print(self.q)
在on_status 方法中,我已将所有数据和status_count 存储在列表中,但是当我尝试迭代数据时,我无法这样做
enter code here
tweet_list=list()
tweet_list.append(myStream.filter(track=[p]))
#tweet_list=myStream.filter(track=[p])
print(len(myStream.filter(track=[p])))
我得到这个结果:
['Chanchinthar', 1063, 'Sourabh', 4424]
Traceback (most recent call last):
File "C:/Users/TharunReddy/Desktop/pothi/twitter.py", line 51, in <module>
print(len(myStream.filter(track=[p])))
TypeError: object of type 'NoneType' has no len()
如何将推文存储在列表中并能够对其进行迭代? 有人请帮忙!
【问题讨论】:
标签: python twitter tweepy twitter-streaming-api