특정 검색어와 관련된 트윗 목록을 살펴보고 모든 해시 태그를 추출하려고합니다. 모든 해시 태그를 포함하는 파이썬 목록을 만들고 싶습니다. 다음과 같이 Twython을 사용하여 시작했습니다.
from twython import Twython
api_key = 'xxxx'
api_secret = 'xxxx'
acces_token = 'xxxx'
ak_secret = 'xxxx'
t = Twython(app_key = api_key, app_secret = api_secret, oauth_token = acces_token, oauth_token_secret = ak_secret)
search = t.search(q = 'Python', count = 10)
tweets = search['statuses']
hashtags = []
for tweet in tweets:
b = (tweet['text'],"\n")
if b.startswith('#'):
hastags.append(b)
작동하지 않는 것 같습니다.
'tuple object has no attribute startswith'라는 오류가 발생합니다.
먼저 모든 상태 목록을 작성하고 언급 된 방법을 사용하여 추출 할 것인지 확실하지 않습니다. 또는 상태 목록을 먼저 작성하지 않고 계속 진행해도됩니다.
감사합니다
맞습니다. 문자열에는 startswith 속성이 있고 튜플에는 없습니다.
마지막 세 줄을 다음과 같이 변경하십시오.
b = (tweet['text'])
if b.startswith("#") is True:
hashtags.append(b)
정말로 줄 바꿈을 원한다면 다음과 같습니다.
b = (tweet['text'] + "\n")
if b.startswith("#") is True:
hashtags.append(b)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다