트위터에서 10000 개의 트윗을 크롤링하고 해시 태그로 특정 단어를 포함하려고합니다.twitter가 파이썬을 사용하기 위해 api로 해시 태그를 크롤링합니다.
예를 들어 해시 태그가 포함 된 #love입니다.
트위터의 모든 해시 태그를 크롤링합니다.
예를 들어 하나의 트윗이 이와 같이 존재합니다.
[내가 졸린 #boring #tired #sleep 오전] 내가 데이터를 크롤링하고,이 같은 결과를보고 싶어요.
"#boring" "#tired" "#sleep"내가 말하고 이해하는 기대
.
파이썬 용 트위터 API를 사용하여 해시 태그를 크롤링하려고했습니다. 이 코드를 실행하면
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를 사용해 보았습니다.
도와주세요.
내 질문을 읽어 주셔서 감사합니다.
오류 메시지를 보셨습니까? 당신은 말 그대로 'print'에 대한 호출에서 괄호가 빠져 있습니다. – Keatinge
@Keatinge 나는 print function python 2.x와 3.x를 사용하여 저의 의견에 대해 저의 실수를 저질렀습니다. –