chadlei
chadlei

Reputation: 189

Does tweepy's search filter allow searching for a substring in a string?

If I am currently searching tweepy.Cursor(api.search, [obama]), will this return tweets that only contain the hashtag #obama but not obama?

What I am trying to ask is whether or not api.search will return tweets that have strings that contain the search term(s) as a substring?

example of what I want: tweepy.Cursor(api.search, [obama]) returns a tweet such as:

greatest president ever! #obama

Upvotes: 4

Views: 185

Answers (1)

AnkushRasgon
AnkushRasgon

Reputation: 820

You need to use #obama if you want to fetch tweets starting with #

tweets = tweepy.Cursor(api.search, ["#obama"]).items(4)
    for tweet in tweets:
        print(tweet.text)

OUTPUT:

RT @afbranco: A.F. Branco Cartoon - Yes We Cage  #KidsInCages #Obama #Obamacages #BorderCrisis
BEHIND THE COMFORT WOMEN CONTROVERSY: HOW LIES BECAME TRUTH / N.Tsutomu #Obama #Clinton #Bush #GOP
RT @christinagala17: @davidaxelrod Can't defend the indefensible.  There was NOT a #MüellerInvestigation. He hired ONE lawyer, you know, yo…
RT @LongDefense: These appear to be the last minute changes made by #Obama Admin days before #Trump took office loosening dissemination of…

Upvotes: 1

Related Questions