我想要在twitter中抓取10000條推文,包含特定字詞和hashtag。twitter使用python抓取api的hashtag
例如,包含hashtag,#love像這樣。
並在推文中抓取所有hashtag。
例如,一條推文像這樣存在。
[我很困#boring #tired #SLEEP]
,我想抓取數據,看看結果是這樣的。
「#boring」 「#tired」 「#SLEEP」
我希望能理解我的意思。
我試圖抓取使用twitter API的python哈希標籤。
但也有一些錯誤
我的代碼如下這樣:
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'])
如何解決這個問題,並檢索推文的所有主題標籤,推文包含特定的主題標籤。
我試過python 3.3.4和windows 8.1 64x。
請幫幫我。
感謝您閱讀我的問題。
你甚至看過錯誤信息嗎?你真的在打電話給'打印'丟失括號 – Keatinge
@Keatinge我混淆了使用打印函數python 2.x和3.x我的錯誤感謝您的評論! –