我试图排除retweets并replies在我的Twython搜索中.
这是我的代码:
from twython import Twython, TwythonError
app_key = "xxxx"
app_secret = "xxxx"
oauth_token = "xxxx"
oauth_token_secret = "xxxx"
naughty_words = [" -RT"]
good_words = ["search phrase", "another search phrase"]
filter = " OR ".join(good_words)
blacklist = " -".join(naughty_words)
keywords = filter + blacklist
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)
search_results = twitter.search(q=keywords, count=100)
Run Code Online (Sandbox Code Playgroud)
问题是该-RT功能并没有真正起作用.
编辑:
我已经尝试了@forge建议,虽然它打印了如果推文不是转推或回复,当我将它们合并到下面的代码中时,机器人仍然会发现推文,转推,引用和回复.
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret) query = 'beer OR wine AND -filter:retweets AND -filter:replies' …Run Code Online (Sandbox Code Playgroud)