Find a certain word in a particular Tweepy user

Asked

Viewed 120 times

0

Following the documentation, I was able to create a code that extracts tweets by tag, and another that extracts tweets from some user. But I’m having trouble extracting tweets from someone by tag.

resultado = [[tweet.id_str, tweet.created_at,tweet.coordinates,tweet.geo,tweet.truncated,tweet.text] for tweet in alltweets if tweet.text == 'palavra_chave']

The code only downloads tweets that contain only the keyword. For example, the keyword is 'Today'. If the tweet is 'Today was a good day', it does not identify.

1 answer

0


This is because you require, in your list comprehension, that the text be exactly equal to the keyword:

... for tweet in alltweets if tweet.text == 'palavra_chave']

If you want to verify that the keyword is inside the tweet, you should use the operator in:

... for tweet in alltweets if 'palavra_chave' in tweet.text]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.