This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlparse, parse_qs | |
# adopted from: | |
# https://stackoverflow.com/questions/45579306/get-youtube-video-url-or-youtube-video-id-from-a-string-using-regex | |
def get_id(url): | |
u_pars = urlparse(url) | |
quer_v = parse_qs(u_pars.query).get('v') | |
if quer_v: | |
return quer_v[0] | |
pth = u_pars.path.split('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import urlparse, parse_qs | |
# source: | |
# https://stackoverflow.com/questions/45579306/get-youtube-video-url-or-youtube-video-id-from-a-string-using-regex | |
def get_id(url): | |
u_pars = urlparse(url) | |
quer_v = parse_qs(u_pars.query).get('v') | |
if quer_v: | |
return quer_v[0] | |
pth = u_pars.path.split('/') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apiclient.discovery import build | |
def build_service(filename): | |
with open(filename) as f: | |
key = f.readline() | |
YOUTUBE_API_SERVICE_NAME = "youtube" | |
YOUTUBE_API_VERSION = "v3" | |
return build(YOUTUBE_API_SERVICE_NAME, | |
YOUTUBE_API_VERSION, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for item in response['items']: | |
comment = item['snippet']['topLevelComment']['snippet']['textDisplay'] | |
comment_id = item['snippet']['topLevelComment']['id'] | |
reply_count = item['snippet']['totalReplyCount'] | |
like_count = item['snippet']['topLevelComment']['snippet']['likeCount'] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Working With Youtube Comments\n", | |
"\n", | |
"## Introduction\n", | |
"\n", |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1 import required libraries | |
import json | |
from csv import writer | |
from apiclient.discovery import build | |
#2 configure function parameters for required variables to pass to service | |
def get_comments(part='snippet', | |
maxResults=100, | |
textFormat='plainText', | |
order='time', |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
OlderNewer