python - 指定推文 Tweepy 返回的数量
问题描述
我正在从公共推文构建一个词云。我已经通过 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
解决方案
默认情况下,使用的标准搜索 APIAPI.search
每页最多返回 15 条推文。
如果您想在每个请求中检索更多,则需要指定count
参数,最多为 100。
如果您想要超过 100 个或保证金额,则需要考虑使用tweepy.Cursor
.
推荐阅读
- python - 我的 python 显示此错误:启动器中的致命错误 [WinError 5] 因为我重命名了我的用户文件夹名称
- javascript - 当变量达到特定值时向所有客户端发出
- html - Rails在body标签内渲染导航栏
- javascript - React Native 在模态中更改虚拟数据的状态
- r - 用 optim() 求方程的最大值
- reactjs - 如何保持 React Native 动画变换状态?
- python - 如何在命令后使不和谐机器人存储/查找消息的其余部分?
- mysql - 试图让 ocelotgui 调试工作
- python - Python django django-crontab 只运行一次。我如何测试它每分钟运行一次?
- python - 麻省理工学院 6.0001 pset1 部分 C