In depth Twitter Search API in tweepy

不问归期 提交于 2020-01-15 10:54:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!