我是一個編程新手,但我希望你能幫助我解決我的問題。我試圖用tweepy/python/stream.api和R(統計程序)來分析推文。如何獲得tweepy輸出到Excel?
知道對不對流偵聽器的工作,但我不能使用輸出...
這是我運行腳本:
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文件中?
如果你打印你所得到的輸出它可能會有所幫助。我只掃描了tweepy網站,我仍然在想你的sapi是什麼類型的對象?是你的問題中的真正關鍵,如果他們是你應該在這裏顯示它們? – PyNEwbie
您是否可以將您的consumer_key,consumer_secret,access_key和access_secret發佈給全世界看? –
我懷疑他切斷了它(因此失去了結束報價),但我刪除了它們,因爲語法高亮讓我瘋狂^^ – poke