简体   繁体   English

为什么我的 count/n 参数将 tweepy 中的 api.search_tweets 限制为 100?

[英]Why does my count/n parameter limit to 100 for api.search_tweets in tweepy?

I want to get at least 10,000 of the most recent tweets containing the word 'bitcoin' using tweepy.我想使用 tweepy 获取至少 10,000 条包含“比特币”一词的最新推文。 I checked the parameters, and people online are saying the number of tweets (count) that tweepy's api.search_tweets() can be up to 18,000... but when i use 10,000 as the count it only returns a list of the 100 most recent tweets.我检查了参数,网上有人说 tweepy 的 api.search_tweets() 的推文数量(计数)可以达到 18,000 ……但是当我使用 10,000 作为计数时,它只返回 100 个最新的列表推文。 I attached some code below to check out.我在下面附上了一些代码以供查看。 Lemme know if anyone knows an answer to this.让我知道是否有人知道这个问题的答案。

# setting my query
search_term = "bitcoin -filter:retweets"
# making a list of all tweets with my query
search_tweets = api.search_tweets(q = search_term, lang = "en", count = 10000)

# shows me how many tweets api.search_tweets() gets
print(f"Number of tweets found: {len(search_tweets)}")

# loops through each tweet in search_tweets and prints information about each tweet
for tweet in search_tweets:
    print(f"{tweet.user.name} tweeted: ")
    print(tweet.text)
    print(f"# of likes: {tweet.favorite_count}")
    print(f'# of retweets: {tweet.retweet_count}')
    print("-------------------------------------------------------------------------------") #seperates each tweet

this outputs this: https://i.stack.imgur.com/BHQuV.png这输出这个: https : //i.stack.imgur.com/BHQuV.png

You can see it works, but we still only get a list of 100 tweets when my count is 18,000...你可以看到它有效,但当我的计数为 18,000 时,我们仍然只能得到 100 条推文的列表......

Did you check the documentation?你检查文档了吗? That request is limited to 100 at a time.该请求一次限制为 100 个。

https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/api-reference/get-search-tweets

count   optional    The number of tweets to return per page, up to a maximum of 100. Defaults to 15. This was formerly the "rpp" parameter in the old Search API.       100

Use tweepy's cursor object get more than 100 tweets.使用tweepy 的游标对象获得 100 多条推文。

Here's an example:下面是一个例子:

n=500

tweets=tweepy.Cursor(api.search_tweets,q="#bitcoin",lang="en",tweet_mode="extended").items(n)


tweets_json=[]
for tweet in tweets:
   tweets_json.append(tweet._json)

This will return a list which contains the tweet info in json format.这将返回一个包含 json 格式的推文信息的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM