bs4
을 가진 후 다음은 당신이 Python YouTube API 사용에 대한 질문 무엇을 달성 :
from gdata.youtube import service
USERNAME = '[email protected]'
PASSWORD = 'a_very_long_password'
VIDEO_ID = 'wf_IIbT8HGk'
def comments_generator(client, video_id):
comment_feed = client.GetYouTubeVideoCommentFeed(video_id=video_id)
while comment_feed is not None:
for comment in comment_feed.entry:
yield comment
next_link = comment_feed.GetNextLink()
if next_link is None:
comment_feed = None
else:
comment_feed = client.GetYouTubeVideoCommentFeed(next_link.href)
client = service.YouTubeService()
client.ClientLogin(USERNAME, PASSWORD)
for comment in comments_generator(client, VIDEO_ID):
author_name = comment.author[0].name.text
text = comment.content.text
print("{}: {}".format(author_name, text))
불행하게도 API가 1000에 검색 할 수있는 항목의 수를 제한합니다. 같은 원리가 API의 다른 피드에서 항목을 검색에 적용해야
gdata.service.RequestError: {'status': 400, 'body': 'You cannot request beyond item 1000.', 'reason': 'Bad Request'}
참고 :이 내가 손으로 불통 버전을 시도 할 때 내가 가진 오류가 GetYouTubeVideoCommentFeed
URL 매개 변수를 제작했다. 당신이 GetYouTubeVideoCommentFeed
URL 매개 변수를 정교하게 손하려면
, 그 형식은 다음과 같습니다
'https://gdata.youtube.com/feeds/api/videos/{video_id}/comments?start-index={start_index}&max-results={max_results}'
다음과 같은 제한 사항이 적용됩니다 start-index <= 1000
및 max-results <= 50
.
이 답변 [이 질문에 대한 답변 (http://stackoverflow.com/questions/10941803/using-youtube-api-to-all-comments-from-a-video-with-the-json-feed) YouTube PHP API에는이를 허용하는 호출이 있으므로 PHP를 사용하는 솔루션으로 필자는 순수한 Python 응답이 없다고 생각합니다. –
@KenB 나는 그것을 보았다. 그것은 수치 스럽습니다. 문제의 비디오에는 9k 개의 댓글이 있으며 360 GetNextLink 호출이 최선의 방법이라고 생각하지 않습니다. – TankorSmash
'www.youtube.com/all_comments? v = video_id' URL은 분석 가능한 댓글 목록이 있지만 긴로드 시간입니다. 내가 그것을 시도 할 수 있다고 가정 해보자. – TankorSmash