how to take all tweets in a hashtag with tweepy?

后端 未结 4 580
余生分开走
余生分开走 2021-02-04 22:53

I\'m trying to take every open tweets in a hashtag but my code does not go further than 299 tweets.

I also trying to take tweets from a specific time line like tweets on

4条回答
  •  天命终不由人
    2021-02-04 23:05

    Have a look at this: https://tweepy.readthedocs.io/en/v3.5.0/cursor_tutorial.html

    And try this:

    import tweepy
    
    auth = tweepy.OAuthHandler(CONSUMER_TOKEN, CONSUMER_SECRET)
    api = tweepy.API(auth)
    
    for tweet in tweepy.Cursor(api.search, q='#python', rpp=100).items():
        # Do something
        pass
    

    In your case you have a max number of tweets to get, so as per the linked tutorial you could do:

    import tweepy
    
    MAX_TWEETS = 5000000000000000000000
    
    auth = tweepy.OAuthHandler(CONSUMER_TOKEN, CONSUMER_SECRET)
    api = tweepy.API(auth)
    
    for tweet in tweepy.Cursor(api.search, q='#python', rpp=100).items(MAX_TWEETS):
        # Do something
        pass
    

    If you want tweets after a given ID, you can also pass that argument.

提交回复
热议问题