如何在不提供搜索查询的情况下返回所有推文 [英] how to return all tweets without providing a search query
问题描述
我正在从事一个文本挖掘项目,用于分析推文.
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.
熟悉tweepy的api.search函数.但是,当我尝试在没有搜索查询的情况下运行它时:
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))
我收到以下消息:出现异常,等待 15 分钟".
i get the following message: "exception raised, waiting 15 minutes".
推荐答案
您可以通过将 *
赋予查询参数来获取所有推文:
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)
如果您需要特定数量的推文,您可以像这样使用 tweepy Cursor:
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)]
这篇关于如何在不提供搜索查询的情况下返回所有推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!