简体   繁体   English

指定推文 Tweepy 返回的数量

[英]Specify amount of Tweets Tweepy returns

I am building a word cloud from public Tweets.我正在从公共推文构建一个词云。 I have connected to the API via Tweepy and have successfully gotten it to return Tweets related to my search term, but for some reason can only get it to return 15 Tweets.我已经通过 Tweepy 连接到 API 并成功让它返回与我的搜索词相关的推文,但由于某种原因只能让它返回 15 条推文。

import pandas as pd

# subject of word cloud
search_term = 'ENTER SEARCH TERM HERE'

# creating dataframe containing the username and corresponding tweet content relating to our search term
df = pd.DataFrame(
    [tweet.user.id, tweet.user.name, tweet.text] for tweet in api.search(q=search_term, lang="en")
)

# renaming columns of data frame
df.rename(columns={0 : 'user id'}, inplace=True)
df.rename(columns={1 : 'screen name'}, inplace=True)
df.rename(columns={2 : 'text'}, inplace=True)
df 

By default, the standard search API that API.search uses returns up to 15 Tweets per page.默认情况下, API.search使用的标准搜索 API每页最多返回 15 条推文。
You need to specify the count parameter, up to a maximum of 100, if you want to retrieve more per request.如果要在每个请求中检索更多,则需要指定count参数,最多为 100。

If you want more than 100 or a guaranteed amount, you'll need to look into paginating usingtweepy.Cursor .如果您想要超过 100 个或保证金额,则需要使用tweepy.Cursor研究分页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM