【问题标题】:How to get twitter data of tweets within a certain time frame?如何获取特定时间范围内推文的推特数据?
【发布时间】:2017-12-12 04:53:16
【问题描述】:

当推文数据回到某个点时,我应该在我的代码中添加什么来强制程序停止打印数据。例如,如何在运行此程序的一个月内获取所有关于 Verratti 的推文?

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import json

access_token = the code
access_token_secret = the code
consumer_key = the code
consumer_secret = the code


#print
class StdOutListener(StreamListener):

    def on_data(self, data):
        print (json.loads(data)['text'])
        return True

    def on_error(self, status):
        print (status)

#find
if __name__ == '__main__':

    #This handles Twitter authetification and the connection to Twitter         Streaming API
    l = StdOutListener()
    auth = OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    stream = Stream(auth, l)

    #This line filter Twitter Streams to capture data by the keywords:     'python', 'javascript', 'ruby'
    stream.filter(track=['Verratti'])

【问题讨论】:

    标签: python json twitter tweepy


    【解决方案1】:

    好问题。事实证明,Twitter API 只允许您从当前日期回溯一周。不过有一种解决方法,有人制作了一个 github 库,可以使用 twitter 的高级搜索功能搜索任何时间范围,您甚至不必费心整个身份验证过程。

    查看:https://github.com/Jefferson-Henrique/GetOldTweets-python

    【讨论】:

      猜你喜欢
      • 2011-03-30
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多