Tweepy API 搜索没有关键字 [英] Tweepy API search doesn't have keyword

查看:46
本文介绍了Tweepy API 搜索没有关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Tweepy(python 的 REST API 客户端),我正在尝试通过多个关键字查找推文,但推文中不包含 url.

I am working with Tweepy (python's REST API client) and I'm trying to find tweets by several keywords and without url included in tweet.

但搜索结果并不令我们满意.看起来查询有错误并已停止.此外,我们还观察到结果是一个一个返回的,而不是(像以前那样)以 100 个散装的形式返回.

But search results are not up to our satisfaction. Looks like query has erros and was stopped. Additionally we had observed that results were returned one-by-one not (as previously) in bulk packs of 100.

你能告诉我为什么这个搜索不能正常工作吗?

Could you please tell me why this search does not work properly?

我们希望获得所有提及亚马逊"的推文,但文本中没有任何 URL 链接.我们使用了如下所示的搜索.搜索结果仍然包含带有 URL 或没有亚马逊"关键字的推文.

We wanted to get all tweets mentioning 'Amazon' without any URL links in the text. We used search shown below. Search results were still containing tweets with URLs or without 'Amazon' keyword.

你能告诉我们我们做错了什么吗?

Could you please let us know what we are doing wrong?

auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
searchQuery = 'Amazon OR AMAZON OR amazon filter:-links' # Keyword

new_tweets = api.search(q=searchQuery, count=100,
                        result_type = "recent",
                        max_id = sinceId,
                        lang = "en") 

推荐答案

减号应该放在filter"之前,而不是links"之前,像这样:searchQuery = '亚马逊或亚马逊或亚马逊 -filter:links'

The minus sign should be put before "filter", not before "links", like this: searchQuery = 'Amazon OR AMAZON OR amazon -filter:links'

另外,我怀疑 count = 100 选项是否有效,因为它没有列在 API 文档(不过可能不是最新的).尝试将其替换为 rpp = 100 以批量获取推文.

Also, I doubt that the count = 100 option is a valid one, since it is not listed on the API documentation (which may not be very up-to-date, though). Try to replace that with rpp = 100 to get tweets in bulk packs.

我不确定为什么您找到的某些推文不包含Amazon"关键字,但有可能是Amazon"包含在发布者的用户名中.我不知道你是否可以直接在查询中过滤它,或者你是否想要过滤它,因为这意味着你会拒绝来自亚马逊官方账户的推文.我建议,对于查询返回的每条推文,您都要检查它以确保它确实包含Amazon".

I am not sure why some of the tweets you find do not contain the "Amazon" keyword, but a possibility is that "Amazon" is contained within the username of the poster. I do not know if you can filter that directly in the query, or even if you would want to filter it, since it would mean you would reject tweets from the official Amazon accounts. I would suggest that, for each tweet the query returns, you check it to make sure it does contain "Amazon".

这篇关于Tweepy API 搜索没有关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆