问题
I wanted to search for tweets "by keyword" from a "given screen name."
Example, all tweets from "BBCNews" about "weather".
Looking into Tweepy library, I found this code:
tweepy.Cursor(api.search,
q="weather",
rpp=100,
result_type="recent",
include_entities=True,
lang="en")
However, how am I gonna filter the tweets such that they are only from BBCNews?
Thank you in advance.
回答1:
The list of options you can use to filter the tweets you find can be found here : https://dev.twitter.com/rest/public/search
You can put them directly in your query, without caring about Tweepy. In your case, I would suggest
tweepy.Cursor(api.search,
q="weather from:BBCNews",
rpp=100,
result_type="recent",
include_entities=True,
lang="en")
You can even add -filter:retweets
to your request to get rid of the retweets.
来源:https://stackoverflow.com/questions/38823430/in-depth-twitter-search-api-in-tweepy