tweepy
v4.0.0
  • Instalacja
  • Pierwsze kroki
  • Poradnik uwierzytelniania
  • Snippety
  • tweepy.API — Twitter API v1.1 Reference
  • tweepy.Client — Twitter API v2 Reference
  • Models Reference
  • tweepy.Stream — Odniesienia do przesyłania strumieniowego
  • tweepy.asynchronous.AsyncStream — Asynchronous Stream Reference
  • Wyjątki
  • Rozszerzone Tweety
  • Pagination
    • API v1.1
      • Example
    • API v2
      • Example
  • Przesyłanie strumieniowe
  • Uruchamianie testów
  • Changelog
tweepy
  • »
  • Pagination
  • Edit on GitHub

Pagination¶

API v1.1¶

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

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

Parametry
  • 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

Parametry

limit – Maximum number of items to iterate over

Zwraca

Iterator to iterate through items

Typ zwracany

ItemIterator

pages(limit=inf)¶

Retrieve the page for each request

Parametry

limit – Maximum number of pages to iterate over

Zwraca

Iterator to iterate through pages

Typ zwracany

CursorIterator or DMCursorIterator or IdIterator or NextIterator or PageIterator

Example¶

import tweepy

auth = tweepy.AppAuthHandler("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))

API v2¶

class tweepy.Paginator(method, *args, **kwargs)¶

Paginator can be used to paginate for any Client methods that support pagination

Parametry
  • method – Client method to paginate for

  • args – Positional arguments to pass to method

  • kwargs – Keyword arguments to pass to method

flatten(limit=inf)¶

Flatten paginated data

Parametry

limit – Maximum number of results to yield

Example¶

import tweepy

client = tweepy.Client("Bearer Token here")

for response in tweepy.Paginator(client.get_users_followers, 2244994945,
                                 max_results=1000, limit=5):
    print(response.meta)

for tweet in tweepy.Paginator(client.search_recent_tweets, "Tweepy",
                              max_results=100).flatten(limit=250):
    print(tweet.id)
Next Previous

© Copyright 2009-2021, Joshua Roesslein. Revision dbb37dcf.

Built with Sphinx using a theme provided by Read the Docs.