如何获得tweepy输出到Excel?

我是一个编程新手,但我希望你能帮我解决我的问题。 我试图用tweepy / python / stream.api和R(统计程序)来分析tweets。

知道stream侦听器正在工作,但我不能使用输出…

这是我正在运行的脚本:

import tweepy consumer_key="..." consumer_secret="..." access_key = "..." access_secret = "..." auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) class CustomStreamListener(tweepy.StreamListener): def on_status(self, status): print status.text def on_error(self, status_code): print >> sys.stderr, 'Encountered error with status code:', status_code return True # Don't kill the stream def on_timeout(self): print >> sys.stderr, 'Timeout...' return True # Don't kill the stream sapi = tweepy.streaming.Stream(auth, CustomStreamListener()) sapi.filter(track=['...']) 

因此,我没有得到完整的推文(只有前50个字符),我不能看到它被啾啾的时间。 我怎样才能解决这个问题,并有可能以某种方式“打印”输出到Excel文件?

将输出写入.csv文件或使用xlrd软件包。 就50个字而言,我不知道。 看起来这与图书馆有关。

更改您的print status.text status.text使用xlwt直接写入excel工作表中的单元格。 我已经对它进行了攻击,没关系,但是你的代码往往会变得非常冗长。

http://pypi.python.org/pypi/xlwt