[英]twitter crawling hashtag with api for using python
i want to crawling 10000 tweet in twitter, contain particular word with hashtag. 我想在Twitter中抓取10000条推文,包含带有标签的特定单词。
for example, contain hashtag, #love like this. 例如,包含#号标签,例如#love。
and crawl all hashtag in tweet. 并在推特中爬行所有主题标签。
for example, one tweet exist like this. 例如,存在一条这样的推文。
[i am sleepy #boring #tired #sleep] [我困了#无聊#累了#睡觉]
and i want to crawl data, and see result like this. 我想抓取数据,并看到这样的结果。
"#boring" "#tired" "#sleep" “ #boring”“ #tired”“ #sleep”
i expect to understand what i am saying. 我希望了解我在说什么。
i tried to crawl hashtag using twitter API for python. 我试图使用Twitter API for python来搜寻主题标签。
but there are some error 但是有一些错误
my code following this: 我的代码如下:
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
#Variables that contains the user credentials to access Twitter API
access_token = "mytoken"
access_token_secret = "mytokenscret"
consumer_key = "consumerkey"
consumer_secret = "consumersecret"
class StdOutListener(StreamListener):
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=['#happy'])
when i run this code, there are popup like this. 当我运行这段代码时,会有这样的弹出窗口。
how to i fix this, and crawl tweet's all hashtag that tweet contain particular hashtag. 我如何解决此问题,并抓取tweet包含特定主题标签的所有主题标签。
i tried python 3.3.4 and windows 8.1 64x. 我尝试了python 3.3.4和Windows 8.1 64x。
please help me. 请帮我。
thanks for read my question. 感谢您阅读我的问题。
似乎您使用的是Python 3.0+,因此无法使用print "Hello world"
,需要使用print("Hello world")
因此只需将print调用更改为带有括号即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.