我要在我的代码中添加什么,才能在推文数据回到特定点时强制程序停止打印数据。例如,如何在运行此程序的一个月内获取所有关于 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'])
最佳答案
好问题。事实证明,Twitter API 只能让您回顾当前日期一周后的情况。不过有一种解决方法,有人制作了一个 github 库,可以使用 Twitter 的高级搜索功能搜索任何时间范围,您甚至不必为整个身份验证过程操心。
查看:https://github.com/Jefferson-Henrique/GetOldTweets-python
关于python - 如何获取特定时间范围内推文的twitter数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44978429/