Python 如何显示hashtag-tweepy?
我想看看所有有特定标签的推特。我这样写代码:Python 如何显示hashtag-tweepy?,python,twitter,stream,hashtag,tweepy,Python,Twitter,Stream,Hashtag,Tweepy,我想看看所有有特定标签的推特。我这样写代码: from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener ckey = 'xxx' csecret = 'xxx' atoken = 'xxx' asecret = 'xxx' class listener(StreamListener): def on_status(self, status
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'
class listener(StreamListener):
def on_status(self, status):
print 'Tweet text: ' + status.text
for hashtag in status.entries['hashtags']:
print hashtag['text']
return True
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(follow=[23], track=["#django"])
跟踪我的一些朋友,跟踪-希望看到带有标签的消息
在我写的一个测试帐户上,我一直在跟踪谁想看的标签。当我运行程序时,python崩溃了
我做错了什么
谢谢您的帮助。Python崩溃时,您会得到什么样的回溯?我没有执行任何回溯程序很长时间,而且不能被Ctrl+C中断。
try something like this:
def on_data(self, data):
jsonData=json.loads(data)
text=jsonData['text']
text2=jsonData['entities']['hashtags']
for hashtag in text2:
text2=hashtag['text']
print text+str(text2)
return True
def on_error(self, status):
print status
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter( track=["django"])