问题描述
tag = 'My_keyword'
# Looping through tweets
for tweet in tweepy.Cursor(api.search,q=tag,).items():
try:
print('\nTweet by: @' + tweet.user.screen_name)
# Retweet tweets as they are found
tweet.retweet()
print('Retweeted the tweet')
sleep(randint(1,2))
except tweepy.TweepError as e:
print(e.reason)
except stopiteration:
break
但是我如何制作关键字黑名单以检查它是否在推文中,跳过推文并转到下一个......?
解决方法
请查看 documentation 以获取更详细的指南。可以通过tweet.full_text
获取推文文本,然后使用字符串比较,可以检查推文文本中是否存在某个词。
if 'bad_word' in tweet.full_text:
continue
如果你有一个单词列表,你可以做类似的事情
If any([bw in tweet.full_text for bw in bad_word_list]):