import tweepy
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
results = api.search(q="Indian Election")
for result in results:
print result.text
我只能下载一些推文,如何下载1000条推文或继续下载推文
答案 0 :(得分:0)
要搜索Twitter并流式传输结果,请使用StreamListener
对象:
来自:https://github.com/tweepy/tweepy/blob/master/examples/streaming.py
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['basketball'])
答案 1 :(得分:0)
检查出来:
http://fidlr.org/post/51968189300/fetching-tweets-using-tweepy
您需要创建一个监听器:
text = []
class LimitedListener(StreamListener):
def on_data(self, data):
if data != '':
text.append(data)
return True