로딩
요청 처리 중입니다...

유튜브 조회수 가져오기

 유튜브 조회수 가져오기

유튜브 조회수를 가져오는 방법은 여러가지가 있다. API를 이용하는 방법도 있고 selenium 를 사용하여 가져오는 방법도 있다.

아래 방법은 페이지 전체를 가져와 자바스크립트 변수인 ytInitialData 를 파싱하여 조회수를 가져오는 방법이다. ytInitialData 변수에는 json 데이터가 들어가 있다. import requests import re import json try: html = requests.get("https://www.youtube.com/watch?v=T5cHCXeweYo").text matched = re.search(r'var ytInitialData = (.*?)}

;', html, re.S) json_string = matched.group(1) + "}" # json을 output_list에 삽입 output_list = json.loads(json_string) print(output_list['contents']['twoColumnWatc...

# 유튜브조회수 # 자바스크립트변수가져오기 # 자바스크립트변수크롤링 # 파이썬