简体   繁体   English

Twitter搜索API查询结果与关键字不匹配

[英]Twitter Search API query results don't match keyword

I'm using Tweepy Cursor to find some tweets. 我正在使用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)

I have noticed that the tweet.text for many of the tweets returned mention "pg", as in the movie ranking, but don't contain my query, "pg&e" at all. 我注意到许多推文的tweet.text提到了“pg”,就像在电影排名中一样,但是根本不包含我的查询“pg&e”。

Why is this? 为什么是这样? Is there a way to get an exact match? 有没有办法获得完全匹配? Also, is there a way to give tweepy.Cursor a list of keywords to search for? 另外,有没有办法给tweepy.Cursor一个关键字列表来搜索?

Thanks! 谢谢!

q="\\"pg&e\\"" will give you what you want. q="\\"pg&e\\""会给你你想要的。 I guess the & is interpreted as an AND by the API, so you have to specify that you want to search for pure text by putting extra quotation marks. 我猜这个&被API解释为AND,所以你必须通过添加额外的引号来指定你想要搜索纯文本。

If you want to search for more keywords, using OR in your query should work, provided the query does not get rejected for being too complex. 如果要搜索更多关键字,则在查询中使用OR应该有效,前提是查询不会因为过于复杂而被拒绝。 Something like q="\\"pg&e\\" OR other_keyword OR \\"exact expression to search\\"" should do the trick. q="\\"pg&e\\" OR other_keyword OR \\"exact expression to search\\""应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM