简体   繁体   中英

Twitter Search API query results don't match keyword

I'm using Tweepy Cursor to find some tweets.

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.

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?

Thanks!

q="\\"pg&e\\"" will give you what you want. 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.

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. Something like q="\\"pg&e\\" OR other_keyword OR \\"exact expression to search\\"" should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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