python - Tweepy 光标搜索查询可以遍历从文件加载的单词列表吗?

标签 python twitter tweepy

我正在尝试让我的机器人能够通过搜索 API 搜索多个关键字。到目前为止我已经:

f = open('swear.txt', 'r')
search = f.read().splitlines()
f.close()

for x in search: #goes through each keyword
    print (x)

numberOfTweets = 5
for tweet in tweepy.Cursor(api.search, q=search).items(numberOfTweets):
    tweet.retweet()

正如所见,搜索保存从文件中读取的字符串,但如何使搜索遍历每个字符串?某种 lambda 函数?谢谢

最佳答案

如果我理解正确的话,您想使用每个单词(在本例中为“x”)通过 tweepy.Cursor 来搜索它们?如果是这样,你的答案就很简单了。

f = open('swear.txt', 'r')
search = f.read().splitlines()
f.close()

numberOfTweets = 5
for x in search: #goes through each keyword
    for tweet in tweepy.Cursor(api.search, q=x).items(numberOfTweets):
        tweet.retweet()

关于python - Tweepy 光标搜索查询可以遍历从文件加载的单词列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56623713/

相关文章:

python - 无法导入 tweepy(Python 3.7 - tweepy 3.5)

python - 如何使用python将三个csv文件数据写入一个具有一个日期列和三个数据列的csv文件

python - 当我尝试使用 cx_freeze 编译时出现导入错误

python - Google Analytics API Python 错误 403 - 权限不足

javascript - 推特分享按钮没有出现

javascript - Conceal Div 内的社交媒体按钮

python - 如何在没有过滤器的情况下使用 tweepy

python - 在Python中使用类作为属性

iOS Twitter 套件使用出现错误 'Request failed: forbidden'

python - Tweepy Streaming - 停止收集 x 数量的推文