https://newbiecs.tistory.com/392
'google-api-python-client'를 사용한 유튜브 데이터 가져오기 - Google Cloud 및 Python 설정 가이드 (1)
안녕하세요. Prography 8기로 활동하고 있습니다. 8기에 저희 팀은 'google-api-python-client' 를 사용하여 유튜버의 영상들을 가져오고, Description 에 적혀있는 재료 정보들로 사용자가 필요한 재료 데이터...
newbiecs.tistory.com
안녕하세요.
이전 글에서는 Google Cloud 및 googleapiclient 설정에 대해 알아봤습니다.
이제 유튜버의 영상 정보를 가져오는 것을 해보겠습니다.
영상 정보란 제목, 설명, 썸네일, 조회수, 좋아요, 업로드날짜, 재생시간 등등을 가져올 수 있습니다.
그러면 본인이 좋아하는 유튜버를 정하면 되겠습니다.
저는 여행을 좋아하고, 빠니보틀과 곽튜브 영상 데이터를 가져와 보겠습니다.
YouTube 플레이리스트 데이터 가져오기

곽튜브의 재생목록을 가져오겠습니다.
사진에 나와있는 title 과 thumbnails 정보를 가져와 보겠습니다.
하지만 우리는 알아야 되는 것이 하나 있습니다.
바로 곽튜브의 channel_id 입니다.
개발자도구를 이용하여 가져올 수도 있지만
아래 사이트를 이용하시면 간단합니다.
곽튜브 영상을 들어가서 URL 복사한 것을 붙여넣기하면 channel_id 값이 나옵니다.

https://ytlarge.com/youtube/channel-id-finder/ko
YouTube 채널 ID 찾기 - 채널 ID 및 정보 찾기
YouTube 사용자 이름 또는 맞춤 URL 또는 동영상에서 YouTube 채널 ID 및 정보를 찾습니다. 채널 ID를 찾는 방법을 알아보세요....
ytlarge.com
우리는 재생목록의 영상들을 가져오고 싶습니다.
그러면 googleapiclient 라이브러리의 문서를 찾아보면 되겠습니다.
링크는 아래와 같습니다.
https://google-api-client-libraries.appspot.com/documentation/youtube/v3/python/latest/
https://google-api-client-libraries.appspot.com/documentation/youtube/v3/python/latest/
Instance Methods activities() Returns the activities Resource. captions() Returns the captions Resource. channelBanners() Returns the channelBanners Resource. channelSections() Returns the channelSections Resource. channels() Returns the channels Resource....
google-api-client-libraries.appspot.com
우리는 재생목록 즉 playlist 값을 가져오면 되겠습니다.
그러면 코드로 작성해볼까요?
import os
import pandas as pd
from googleapiclient.discovery import build
class YouTube:
def __init__(self):
developer_key = os.getenv('YOUTUBE_DEVELOPER_KEY')
youtube_api_service_name = 'youtube'
youtube_api_version = 'v3'
self.youtube = build(youtube_api_service_name, youtube_api_version, developerKey=developer_key)
def youtuber(self, channel_id: str) -> list:
playlist = self.youtube.playlists().list(
channelId=channel_id,
part='snippet',
maxResults=20
).execute()
print(len(playlist['items']))
return playlist['items']
여기서 중요한 것은 maxResults 입니다.
결과 값을 최대한 늘려줘야 합니다.
결과 값은 아래와 같습니다.
print(len(playlist['items'])) 리스트의 숫자는 14개로
맨 위 사진의 영상 갯 수와 똑같은 걸 확인할 수 있습니다.
[{'kind': 'youtube#playlist', 'etag': 'eW3N1BHmxl9_qGxY7pOWIc6Iz7Q', 'id': 'PLhbjbu4_zxgsfinWBF2xNpKSgxSk1N4pc', 'snippet': {'publishedAt': '2023-07-27T23:34:12Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '북중미(2023)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/bD24W0FfH0M/default.jpg', 'width': 120, 'height': 90}, 'mum': {'url': 'https://i.ytimg.com/vi/bD24W0FfH0M/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/bD24W0FfH0M/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/bD24W0FfH0M/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/bD24W0FfH0M/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '북중미(2023)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': 'D_-q5S9I7Kve0j7oHCfxc', 'id': 'PLhbjbu4_zxguER52goUaAzb_bEnoC7-5r', 'snippet': {'publishedAt': '2023-03-23T07:43:03Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '찐따록 : 인간 곽준빈', 'descript, 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/9u-33POsiV4/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/9u-33POsiV4/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/9u-33POsiV4/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/9u-33POsiV4/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/9u-33POsiV4/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브',ocalized': {'title': '찐따록 : 인간 곽준빈', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': 'aiLa15SdJF5PV7utSafHMx28iyY', 'id': 'PLhbjbu4_zxgs0iTjxHP2TXcqf_i4EJKtw', 'sn{'publishedAt': '2022-09-01T09:03:16Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '일본여행(2022)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/49tjroGV8nk/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/49tjroGV8nk/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/49tjroGV8nk/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/49tjroGV8nk/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/49tjroGV8nk/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '일본여행(2022)', 'description': {'kind': 'youtube#playlist', 'etag': '2Z65GBkG6lyP1gW55VdUFpuwO8k', 'id': 'PLhbjbu4_zxguFPUE8Br5WSwXDkpLhWCG1', 'snippet': {'publishedAt': '2022-07-01T10:30:17Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '우즈베키스탄(2022)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/rSyxycgYqvg/default.jpg', 'width': 120, 'height': 90dium': {'url': 'https://i.ytimg.com/vi/rSyxycgYqvg/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/rSyxycgYqvg/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/rSyxycgYqvg/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/rSyxycgYqvg/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '우즈베키스탄(2022)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': 'oME53Cm1CgTqIklTgM', 'id': 'PLhbjbu4_zxgvhSHJhCE80Al4_w8pzwn7g', 'snippet': {'publishedAt': '2022-03-15T08:35:20Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '서울 자취(2022)', 'descript: '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/FdShcIR3588/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/FdShcIR3588/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/FdShcIR3588/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/FdShcIR3588/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/FdShcIR3588/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜, 'localized': {'title': '서울 자취(2022)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': '3528pPZKjf6UhUk2gBqQYC0X6vY', 'id': 'PLhbjbu4_zxgsqDsUdTj0EPYUY4MNa4vUT', 'sni': {'publishedAt': '2021-07-14T09:56:20Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '세계여행(2021)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.ci/LbQ7Ewlq3aE/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/LbQ7Ewlq3aE/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/LbQ7Ewlq3aE/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/LbQ7Ewlq3aE/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/LbQ7Ewlq3aE/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '세계여행(2021)', 'description': ''kind': 'youtube#playlist', 'etag': '-AbR_rQTprBOMlYAuy5uYwoZ3n4', 'id': 'PLhbjbu4_zxgvlC8Qh816685BbKNvNKDj9', 'snippet': {'publishedAt': '2021-05-12T13:33:47Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '에티오피아 여행(2021)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/KtU5pAauLuE/default.jpg', 'width': 120, 'height': edium': {'url': 'https://i.ytimg.com/vi/KtU5pAauLuE/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/KtU5pAauLuE/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/KtU5pAauLuE/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/KtU5pAauLuE/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '에티오피아 여행(2021)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': 'QY_Dq9e9wP2IidMGGaiS-cV1VGY', 'id': 'PLhbjbu4_zxgsrN9NyJFfdaEUZIFZD6-5Y', 'snippet': {'publishedAt': '2021-03-27T11:19:19Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '서울 자취(2021'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/RXW-h_ci02U/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/RXW-h_ci02U/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/RXW-h_ci02U/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/RXW-h_ci02U/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/RXW-h_ci02U/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '서울 자취(2021)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': '4FWusfErd5ldZNkmU0cBg4-Wg_8', 'id': 'PLhbjbu4_zxgsbiivU3qeYcf-lk', 'snippet': {'publishedAt': '2021-01-21T15:27:37Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '다이어트 시리즈', 'description': '', 'thumbnails': {'default': {'url': 'httytimg.com/vi/wV1nf_JqNYo/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/wV1nf_JqNYo/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/wV1nf_JqNYo/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/wV1nf_JqNYo/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/wV1nf_JqNYo/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '다이어트 시리즈', 'des ''}}}, {'kind': 'youtube#playlist', 'etag': 'JDKVYFhD3mRtiS90z5v_L1nhvDo', 'id': 'PLhbjbu4_zxgtVw1GCmGtvVmIRoqqMYxkE', 'snippet': {'publishedAt': '2021-01-21T15:26:04Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '한국 겨울 여행(2021)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/PUSlUv74caQ/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/PUSlUv74caQ/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/PUSlUv74caQ/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/PUSlUv74caQ/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/PUSlUv74caQ/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '한국 겨울 여행(2021)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etRG3pfQyDnC8ptR2CGsaEgf88', 'id': 'PLhbjbu4_zxgvj-IALls9DqHHY_Cg-iKQG', 'snippet': {'publishedAt': '2020-07-02T10:53:40Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '한국 전국020)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/valwrFtlzRc/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/valwrFtlzRc/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/valwrFtlzRc/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/valwrFtlzRc/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/valwrFtlzRc/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '한국 전국여행(2020)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': '77FFaUDmaWqEsDDMKDOoGZ9yaYc', 'id': 'PLhbjbu4_zxgtpQnqeJtR_1uT', 'snippet': {'publishedAt': '2020-03-24T02:13:57Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '러시아 겨울여행(2020)', 'description': '', 'thumbnails': {'defaultl': 'https://i.ytimg.com/vi/hNHFBWmzKqk/default.jpg', 'width': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/hNHFBWmzKqk/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/hNHFBWmzKqk/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/hNHFBWmzKqk/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/hNHFBWmzKqk/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '러시아 020)', 'description': ''}}}, {'kind': 'youtube#playlist', 'etag': '0DdbH8oOIaGsmIzCfqylG2jP5gI', 'id': 'PLhbjbu4_zxgvFmrO_zFwHKdLBA53Qqp-l', 'snippet': {'publishedAt': '2020-03-24T02:12:59Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '한국 먹방(2020)', 'description': '', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/VN8r0FALYUs/default.jpg', th': 120, 'height': 90}, 'medium': {'url': 'https://i.ytimg.com/vi/VN8r0FALYUs/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/VN8r0FALYUs/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/VN8r0FALYUs/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/VN8r0FALYUs/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '한국 먹방(2020)', 'description': ''}}}, {'kind': 'youtube#playlisag': 'vRJ8YWWbnEr-kNCNfyq_bE0ldlU', 'id': 'PLhbjbu4_zxgv0PsKGOqFgYuXJyX5v7WWo', 'snippet': {'publishedAt': '2020-03-24T02:11:46Z', 'channelId': 'UClRNDVO8093rmRTtLe4GEPw', 'title': '아제르바이잔 생활기(2019)', 'description': '아제르바이잔에 살면서 가보고 먹고 즐겼던 영상모음입니다.', 'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/p13MST9cAXk/default.j'medium': {'url': 'https://i.ytimg.com/vi/p13MST9cAXk/mqdefault.jpg', 'width': 320, 'height': 180}, 'high': {'url': 'https://i.ytimg.com/vi/p13MST9cAXk/hqdefault.jpg', 'width': 480, 'height': 360}, 'standard': {'url': 'https://i.ytimg.com/vi/p13MST9cAXk/sddefault.jpg', 'width': 640, 'height': 480}, 'maxres': {'url': 'https://i.ytimg.com/vi/p13MST9cAXk/maxresdefault.jpg', 'width': 1280, 'height': 720}}, 'channelTitle': '곽튜브', 'localized': {'title': '아제르바이잔 생활기(2019)', 'description': '아제르바이잔에 살면서 가보고 먹고 즐겼던 영상모음입니다.'}}}]
pandas
googleapiclient 로 얻은 값이 리스트 안에 딕셔너리 형태인 것을 확인 했습니다.
그럼 for 문을 돌리면 되겠군요?!
하지만 pandas 의 경우 for 문으로 돌리는 것은 동작하지 않습니다.
모은 데이터로 csv 를 만드는 경우가 대부분이기 때문에
실시간으로 반복문을 돌려서 csv 를 만든다? 불가능합니다.
그럼 코드를 한번 살펴볼까요?
def make_csv(self, playlist: list, channel_name: str):
lst_title = []
lst_thumbnails = []
for pl in playlist:
lst_title.append(pl['snippet']['title'])
lst_thumbnails.append(pl['snippet']['thumbnails']['default']['url'])
df = pd.DataFrame(
{
"title": lst_title,
"thumbnails": lst_thumbnails
}
)
df.to_csv(f"/Users/cslee/vscode/get-youtube-data/csv/{channel_name}.csv")
lst_title, lst_thumbnails 값을 DataFrame 으로 변환합니다.
DataFrame 을 CSV 파일로 저장합니다.

좋습니다!
argparse
argparse는 Python의 표준 라이브러리 중 하나로,
명령행 인터페이스(Command Line Interface, CLI)를 파싱하고 해석하는 데 사용되는 모듈입니다.
argparse를 사용하면 Python 스크립트를 명령줄에서 더 쉽게 실행하고
사용자에게 명령줄 옵션과 인수를 제공하거나 설명할 수 있습니다.
바로 코드 작성해보겠습니다.
parser = argparse.ArgumentParser(description="유튜브 채널 이름을 입력해 주세요. EX) 곽튜브, 빠니보틀")
parser.add_argument('-c', '--channel')
args = parser.parse_args()
youtube = YouTube()
if args.channel == '빠니보틀':
target = youtube.youtuber(channel_id='UCNhofiqfw5nl-NeDJkXtPvw')
youtube.make_csv(target, channel_name='빠니보틀')
elif args.channel == '곽튜브':
target = youtube.youtuber(channel_id='UClRNDVO8093rmRTtLe4GEPw')
youtube.make_csv(target, channel_name='곽튜브')
else:
print("유튜브 채널 이름을 입력해 주세요.")
argparse 를 사용하여 스크립트에 추가 옵션을 만들어줬습니다.
poetry run python get_test_data.py -c 곽튜브
전체 코드는 아래와 같습니다.
import os
import argparse
import pandas as pd
from googleapiclient.discovery import build
class YouTube:
def __init__(self):
developer_key = os.getenv('YOUTUBE_DEVELOPER_KEY')
youtube_api_service_name = 'youtube'
youtube_api_version = 'v3'
self.youtube = build(youtube_api_service_name, youtube_api_version, developerKey=developer_key)
def youtuber(self, channel_id: str) -> list:
playlist = self.youtube.playlists().list(
channelId=channel_id,
part='snippet',
maxResults=20
).execute()
return playlist['items']
def make_csv(self, playlist: list, channel_name: str):
lst_title = []
lst_thumbnails = []
for pl in playlist:
lst_title.append(pl['snippet']['title'])
lst_thumbnails.append(pl['snippet']['thumbnails']['default']['url'])
df = pd.DataFrame(
{
"title": lst_title,
"thumbnails": lst_thumbnails
}
)
df.to_csv(f"/Users/cslee/vscode/get-youtube-data/csv/{channel_name}.csv")
parser = argparse.ArgumentParser(description="유튜브 채널 이름을 입력해 주세요. EX) 곽튜브, 빠니보틀")
parser.add_argument('-c', '--channel')
args = parser.parse_args()
youtube = YouTube()
if args.channel == '빠니보틀':
target = youtube.youtuber(channel_id='UCNhofiqfw5nl-NeDJkXtPvw')
youtube.make_csv(target, channel_name='빠니보틀')
elif args.channel == '곽튜브':
target = youtube.youtuber(channel_id='UClRNDVO8093rmRTtLe4GEPw')
youtube.make_csv(target, channel_name='곽튜브')
else:
print("유튜브 채널 이름을 입력해 주세요.")
googleapiclient 로 유튜브 데이터를 가져왔습니다.
pandas 로 가져온 정보를 CSV 파일로 추출하였습니다.
argparse 로 스크립트를 더 유연하게 만들었습니다.
다음 게시글에서는 재생목록에 있는 영상들의 정보를 가져와 보겠습니다.
그리고 처음에 얘기 했던 좋아요, 조회수, 등등의 정보도 같이 출력해보겠습니다.
궁금한 점이나 수정해야 될 부분이 있으면 말씀해주시면 감사하겠습니다.
'Language > Python' 카테고리의 다른 글
'google-api-python-client'를 사용한 유튜브 데이터 가져오기 (3) (0) | 2023.09.04 |
---|---|
'google-api-python-client'를 사용한 유튜브 데이터 가져오기 - Google Cloud 및 Python 설정 가이드 (1) (0) | 2023.08.24 |
Python 나무위키 데이터 가져오기 (Pandas, datasets, parquet) (0) | 2023.06.23 |
[PostgreSQL] sorry, too many clients already 문제 해결 (0) | 2023.02.23 |
Python 구글 뉴스 데이터 크롤링(apscheduler, nohup) - 2 (0) | 2023.02.14 |
댓글