[PR]

Pagination

class tweepy.Cursor(method, *args, **kwargs)

Cursor can be used to paginate for any API methods that support pagination

パラメータ:
  • method -- API method to paginate for

  • args -- Positional arguments to pass to method

  • kwargs -- Keyword arguments to pass to method

items(limit=inf)

Retrieve the items in each page/request

パラメータ:

limit -- Maximum number of items to iterate over

戻り値:

Iterator to iterate through items

戻り値の型:

ItemIterator

pages(limit=inf)

Retrieve the page for each request

パラメータ:

limit -- Maximum number of pages to iterate over

戻り値:

Iterator to iterate through pages

戻り値の型:

CursorIterator or DMCursorIterator or IdIterator or NextIterator or PageIterator

Example

import tweepy

auth = tweepy.OAuth2AppHandler("Consumer Key here", "Consumer Secret here")
api = tweepy.API(auth)

for status in tweepy.Cursor(api.search_tweets, "Tweepy",
                            count=100).items(250):
    print(status.id)

for page in tweepy.Cursor(api.get_followers, screen_name="TwitterDev",
                            count=200).pages(5):
    print(len(page))