Tweepy 游标搜索查询可以遍历从文件加载的单词列表吗?
Can the Tweepy cursor search query go through a list of words loaded from a file?
我试图让我的机器人能够通过搜索 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()
我试图让我的机器人能够通过搜索 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()