【问题标题】:Extracting all tweets on a topic from yesterday using Python's Tweepy?使用 Python 的 Tweepy 提取昨天关于某个主题的所有推文?
【发布时间】:2014-11-09 16:54:00
【问题描述】:

似乎 Python API 允许人们挖掘几天前发布的推文。由于我不需要即时流式传输推文,但我想在一段时间内收集关于特定主题(即:快车)的所有推文,我认为运行一个 python 脚本收集“昨天”中关于某个主题的所有推文将做。下面的代码做了类似的事情,但我只能得到一个预先指定的数量(即:200),我可以将这个数字提高到非常大(即:50,000),但是有没有更好的方法来捕获所有的推文前一天的话题?

import tweepy
import time

ckey = ""
csecret = ""
atoken = ""
asecret = ""

OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
    'access_token_key':atoken, 'access_token_secret':asecret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)

# Extract the first "xxx" tweets related to "fast car"
for tweet in tweepy.Cursor(api.search, q='fast-car', since='2014-09-14', until='2014-09-15').items(200): # need to figure out how to extract all tweets in the previous day
    if tweet.geo != None:
        print "////////////////////////////////"
        print "Tweet created:", tweet.created_at
        print ""

【问题讨论】:

    标签: python-2.7 twitter tweepy social-media


    【解决方案1】:

    为了尝试回答这个问题,我可以将检索到的项目数设置为一个假设的巨大数字,例如 items(999999999),一旦脚本提取了前一天的所有推文,它就会自动停止。

    【讨论】:

      【解决方案2】:

      只是不要将任何数字作为参数,它将全部返回。

      【讨论】:

      • 当你最后不提供 .items(200) 时,你会得到一个错误'Cursor' object is not iterable
      猜你喜欢
      • 1970-01-01
      • 2017-12-10
      • 2020-09-04
      • 1970-01-01
      • 2018-12-31
      • 2022-08-11
      • 1970-01-01
      • 2015-01-30
      • 1970-01-01
      相关资源
      最近更新 更多