小编B. *_*has的帖子

Twitter API:如何在使用Twython搜索推文时排除转推

我试图排除retweetsreplies在我的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)

python twitter twython

3
推荐指数
1
解决办法
5718
查看次数

标签 统计

python ×1

twitter ×1

twython ×1