1

I use twitter-python search API to retrieve search results like below

import twitter
api = twitter.Api()
i = 1
result = api.GetSearch("Avatar", page=i)
print [s.text for s in result]

The code above means I want to get the result on first page returned. I tried multiple assignment of i they all work. But I don't know what is the maxium value of i can I assign. Any idea?

Peiti Li
  • 4,634
  • 9
  • 40
  • 57

1 Answers1

1

The maximum value is going to depend on the query, and how many pages twitter feels like giving you.

What about using try/except?

import twitter
api = twitter.Api()

# try a large page number:
i = 181

try:
    result = api.GetSearch("Avatar", page=i)
    print [s.text for s in result]
except:
    print 'page is out of range'
Matt Sweeney
  • 2,060
  • 1
  • 14
  • 19