Question

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?

Was it helpful?

Solution

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'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top