【问题标题】:Searching for tweets in last 24 hours from specific accounts with twitter API in python在 python 中使用 twitter API 从特定帐户搜索过去 24 小时内的推文
【发布时间】:2018-06-04 12:01:36
【问题描述】:

如果我只想要过去 24 小时的结果,我应该输入什么而不是“2016-11-25”/“2016-11-27”?我也只想要来自某些特定帐户的推文,那么我应该在 api 搜索中写什么?

for tweet in tweepy.Cursor(api.search,
                       q='giveaway',
                       since='2016-11-25',
                       until='2016-11-27',
                       ).items(10):
print('Tweet by: @' + tweet.user.screen_name)

【问题讨论】:

标签: python api twitter bots


【解决方案1】:

使用日期时间模块

from datetime import datetime, timedelta

now = datetime.today().now()
prev=now-timedelta(days=1)
now=now.strftime("%Y-%m-%d")
prev=prev.strftime("%Y-%m-%d")

for tweet in tweepy.Cursor(api.search,
                   q='giveaway',
                   since=prev
                   until=now
                   ).items(10):
print('Tweet by: @' + tweet.user.screen_name)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 2018-02-13
    • 2013-02-26
    • 1970-01-01
    • 2017-02-27
    • 2018-10-09
    • 2016-03-02
    相关资源
    最近更新 更多