how to return all tweets without providing a search query

本小妞迷上赌 提交于 2019-12-12 03:54:35

问题


I am working on a text mining project that deals with analyzing tweets.

I would like to get all tweets tweeted in english during a short period of time(not more than a day), without having the result matching to a specific search query, trend, or user criteria.

I am familiar with tweepy's api.search function. However, when i try to run it without a search query:

api.search(count=remaining_tweets, since_id=str(since_id),lang='en', max_id=str(max_id-1))

i get the following message: "exception raised, waiting 15 minutes".


回答1:


You can get all the tweet by giving * to the query parameter:

tweets = api.search(q='*', lang='en', count=200, since_id=since_id, max_id=max_id)

If you need a specific number of tweets, you could use tweepy Cursor like this:

# Get 1000 English tweets from max_id
tweets = [tweet for tweet in tweepy.Cursor(
    api.search, q='*', lang='en', count=200, max_id=max_id).items(1000)]


来源:https://stackoverflow.com/questions/41449870/how-to-return-all-tweets-without-providing-a-search-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!