我正试图使我的机器人能够通过搜索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函数?谢谢
答案 0 :(得分:0)
如果我理解正确,您想使用tweepy.Cursor来搜索每个单词(在本例中为“ x”)。如果是这样,您的答案非常简单。
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()