개발자
틱톡 해시태그 크롤링을 하려는데 An error occurred: Trending() takes no arguments 계속 이런 오류가 나오네요 뭐가 문제인지 모르겠습니다 from TikTokApi import TikTokApi def crawl_tirtir_hashtag(count=10): try: api = TikTokApi() # Get trending videos for 'tirtir' hashtag tiktoks = api.trending(count=count, hashtag='tirtir', lang='en') for tiktok in tiktoks: print("Username:", tiktok['author']['uniqueId']) print("Video URL:", tiktok['video']['playAddr']) print("Description:", tiktok['desc']) print("Hashtags:", tiktok['challenges']) print("\n---\n") except Exception as e: print(f"An error occurred: {e}") # Example usage crawl_tirtir_hashtag(count=5)
답변 0
첫 답변을 기다리고 있어요.
지금 가입하면 모든 질문의 답변을 볼 수 있어요!
현직자들의 명쾌한 답변을 얻을 수 있어요.
이미 회원이신가요?
커리어리 AI 봇
GPT가 달아주는 답변입니다.
2024년 01월 10일
당신의 코드에 문제가 있는 것 같습니다. TikTokApi의 trending 메소드는 인수를 받지 않기 때문입니다. 이는 "Trending() takes no arguments"라는 오류 메시지에서 알 수 있습니다. 해시태그에 대한 동영상을 검색하려면 'get_tiktoks_by_hashtag' 메소드를 사용해야 합니다. 수정된 틱톡 해시태그 크롤링을 진행하는 코드 예제입니다. ```python from TikTokApi import TikTokApi def crawl_tirtir_hashtag(count=10): try: api = TikTokApi() # Get trending videos for 'tirtir' hashtag tiktoks = api.get_tiktoks_by_hashtag('tirtir', count=count) for tiktok in tiktoks['collector']: print("Username:", tiktok['author']['uniqueId']) print("Video URL:", tiktok['video']['playAddr']) print("Description:", tiktok['desc']) print("Hashtags:", [x['title'] for x in tiktok['challenges']]) print("\n---\n") except Exception as e: print(f"An error occurred: {e}") # Example usage crawl_tirtir_hashtag(count=5) ``` 이 코드는 '#tirtir' 해시태그에 대한 동영상을 최대 5개 검색합니다. 결과로 계정 이름, 비디오 URL, 설명 그리고 사용된 해시태그들을 출력합니다.
지금 가입하면 모든 질문의 답변을 볼 수 있어요!