簡體   English   中英

Tweepy 按日期獲取推文

[英]Tweepy get tweets by date

我想在日期之間獲取某個主題的推文。 這在 tweepy 中可能嗎? (或任何其他用於 twitter 的 API?)

我可以通過使用 ID 讓它為 user_timeline 工作,但是當我將它更改為使用 api.search 時,程序基本上只是繼續運行而沒有任何輸出

def getTweets(username):
    tweets = []
    tmpTweets = api.user_timeline(username, tweet_mode = 'extended', include_rts=True)
    for tweet in tmpTweets:
        if tweet.created_at < endDate and tweet.created_at > startDate:
            tweets.append(tweet)

        while (tmpTweets[-1].created_at > startDate):
            tmpTweets = api.user_timeline(username, max_id = tmpTweets[-1].id,tweet_mode = 'extended')
            for tweet in tmpTweets:
                if tweet.created_at < endDate and tweet.created_at > startDate:
                    tweets.append(tweet)
    return tweets

tl; dr: python 中有沒有辦法根據關鍵字搜索在兩個日期之間獲取推文?

使用游標怎么樣:

text_query = 'Coronavirus'
since_date = '2020-02-10'
until_date = '2020-08-10'
max_tweets = 150

# Creation of query method using parameters
tweets = tweepy.Cursor(api.search,q=text_query, since=since_date, until=until_date).items(max_tweets)

在此博客和此答案中也有描述。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM