Filtering in tweepy

倾然丶 夕夏残阳落幕 提交于 2019-12-07 16:50:15

问题


I am new to tweepy and have encountered a problem. I want to download tweets with special hashtags. But it seems

stream.filter(track = ['word1', 'word2', 'word3']) 

looks for these words in tweet and not in hashtags of the tweet. How can I filter on hashtags?


回答1:


You find the tags in the status object. It is there you have to make the comparison with the ones you are looking for.

example:

for hashtag in status.entities['hashtags']:
    print(hashtag['text'])

example here: http://www.pythoncentral.io/introduction-to-tweepy-twitter-for-python/




回答2:


You can actually filter tweets based on your special hashtag.

stream.filter(track=['#MySpecialHashtag', '#AlsoThisHashtag'])

This will pick up only tweets that contain the hashtags you provide as part of the tweet text and save you from arbitrarily collecting tweets and checking if the hashtag field has your hashtag in it.



来源:https://stackoverflow.com/questions/28497731/filtering-in-tweepy

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