Python Tweepy(Twitter API)未返回所有搜索结果
我使用tweepyfortwitter的搜索功能,出于某种原因,搜索结果限制在15个。这是我的密码Python Tweepy(Twitter API)未返回所有搜索结果,python,search,twitter,tweepy,Python,Search,Twitter,Tweepy,我使用tweepyfortwitter的搜索功能,出于某种原因,搜索结果限制在15个。这是我的密码 results=api.search(q="Football",rpp=1000) for result in results: print "%s" %(clNormalizeString(result.text)) print len(results) 只返回15个结果。它是否与不同页面的结果或其他内容有关?问题更多的是关于Twitter API,而不是tweepy本身 根据,c
results=api.search(q="Football",rpp=1000)
for result in results:
print "%s" %(clNormalizeString(result.text))
print len(results)
只返回15个结果。它是否与不同页面的结果或其他内容有关?问题更多的是关于Twitter API,而不是tweepy本身 根据,
count
参数定义:
每页返回的推文数,最多100条。
默认值为15。这以前是旧版本中的“rpp”参数
搜索API
仅供参考,您可以使用tweepy.Cursor
获得分页结果,如下所示:
import tweepy
auth = tweepy.OAuthHandler(..., ...)
auth.set_access_token(..., ...)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search,
q="google",
count=100,
result_type="recent",
include_entities=True,
lang="en").items():
print tweet.created_at, tweet.text
另见:
希望这能有所帮助。这里有一个简单的工作示例(一旦你用真钥匙替换假钥匙)
看起来有一个count参数控制结果的数量,但是有没有办法只显示所有的结果呢?我是通过使用参数“count”而不是“rpp”默认加载(15)得到的
import tweepy
from math import ceil
def get_authorization():
info = {"consumer_key": "A7055154EEFAKE31BD4E4F3B01F679",
"consumer_secret": "C8578274816FAEBEB3B5054447B6046F34B41F52",
"access_token": "15225728-3TtzidHIj6HCLBsaKX7fNpuEUGWHHmQJGeF",
"access_secret": "61E3D5BD2E1341FFD235DF58B9E2FC2C22BADAD0"}
auth = tweepy.OAuthHandler(info['consumer_key'], info['consumer_secret'])
auth.set_access_token(info['access_token'], info['access_secret'])
return auth
def get_tweets(query, n):
_max_queries = 100 # arbitrarily chosen value
api = tweepy.API(get_authorization())
tweets = tweet_batch = api.search(q=query, count=n)
ct = 1
while len(tweets) < n and ct < _max_queries:
print(len(tweets))
tweet_batch = api.search(q=query,
count=n - len(tweets),
max_id=tweet_batch.max_id)
tweets.extend(tweet_batch)
ct += 1
return tweets
api = tweepy.API(get_authorization(), wait_on_rate_limit=True)