python - Twitter Search API 查询结果与关键字不匹配

标签 python api search twitter tweepy

我正在使用 Tweepy Cursor 查找一些推文。

for tweet in tweepy.Cursor(api.search, q='pg&e', count=100, lang='en', since=sinceDate, until=untilDate).items():
    print str(tweet.created_at) + '\t' + str(tweet.text)

我注意到许多推文的 tweet.text 返回了“pg”,如电影排名中所示,但根本不包含我的查询“pg&e”。

这是为什么呢?有没有办法获得精确匹配?另外,有没有办法给 tweepy.Cursor 一个要搜索的关键字列表?

谢谢!

最佳答案

q="\"pg&e\"" 会给你你想要的。我猜 API 将 & 解释为 AND,因此您必须通过添加额外的引号来指定要搜索纯文本。

如果您想搜索更多关键字,在查询中使用 OR 应该可行,前提是查询不会因过于复杂而被拒绝。像 q="\"pg&e\"OR other_keyword OR\"要搜索的精确表达式\"" 这样的东西应该可以解决问题。

关于python - Twitter Search API 查询结果与关键字不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39601524/

相关文章:

python - conda 锻造 : Why does Conda inconsistently want to downgrade NumPy?

c# - Postman 错误 : "Unable to verify the first certificate" when try to get from my .net core api

Jquery 在 iframe 中搜索文本

search - 有关搜索结果的Elasticsearch相关性的问题

python - PyCUDA 内核计时错误

Python:套接字:处理蜂窝网络上的 TCP 连接

rest - PayPal REST API 使用模板创建发票

javascript - 在 React 中显示多个 API 响应

c++ - 如何在 "std::vector<char>"容器中查找单个单词

python - 检测列中两个连续的空值