【问题标题】:Specify amount of Tweets Tweepy returns指定推文 Tweepy 返回的数量
【发布时间】:2020-12-03 21:03:48
【问题描述】:

我正在从公共推文构建一个词云。我已经通过 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 

【问题讨论】:

标签: python pandas twitter tweepy word-cloud


【解决方案1】:

默认情况下,API.search 使用的standard search API 每页最多返回 15 条推文。
如果您想在每个请求中检索更多,则需要指定 count 参数,最大为 100。

如果您想要超过 100 个或保证金额,则需要考虑使用 tweepy.Cursor 进行分页。

【讨论】:

    猜你喜欢
    • 2021-03-28
    • 2016-09-20
    • 2018-10-20
    • 1970-01-01
    • 2011-12-04
    • 2014-10-24
    • 2016-10-20
    • 2015-12-19
    • 1970-01-01
    相关资源
    最近更新 更多