빅데이터/자동화
[자동화] pytchat 을 통한 유투브 라이브 댓글 크롤링
pbj0812
2021. 10. 12. 00:18
- 해당 코드는 pytchat 0.5.5 공식 문서를 그대로 옮긴 것 임을 먼저 밝힙니다.
0. 목표
- pytchat 을 통한 유투브 라이브 댓글 크롤링
1. 실습
1) pytchat 설치
pip install pytchat
* 이미 설치하신 분 들 중 버전이 낮아서 안되는 분들은 업그레이드 필요
pip install --upgrade pytchat==0.5.5
2) library 호출
import pytchat
3) video_id 구하기
- 구하고자 하는 유투브 라이브 방송의 url 중 v= 이후 문자(여기서는 2p-7_CSQ1eU 가 video_id)
4) 코드 실행
chat = pytchat.create(video_id="위에서 구한 video_id 입력")
while chat.is_alive():
for c in chat.get().sync_items():
print(f"{c.datetime} [{c.author.name}]- {c.message}")
5) 결과
(1) 실제 유투브 라이브 댓글 창
(2) 코드 실행 결과