使用Python的Tweepy从昨天提取关于某个主题的所有推文?

问题描述 投票:0回答:2

似乎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
2个回答
0
投票

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


-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.