Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

youtube comments scrape r

devtools::install_github("ropensci/RSelenium") # Install from github

library(RSelenium)
library(rvest)
pJS <- phantom(pjs_cmd = "PATH TO phantomjs.exe") # as i am using windows
Sys.sleep(5) # give the binary a moment
remDr <- remoteDriver(browserName = 'phantomjs')
remDr$open()
remDr$navigate("https://www.youtube.com/watch?v=qRC4Vk6kisY")
remDr$getTitle()[[1]] # [1] "YouTube"

# scroll down
for(i in 1:5){      
  remDr$executeScript(paste("scroll(0,",i*10000,");"))
  Sys.sleep(3)    
}

# Get page source and parse it via rvest
page_source <- remDr$getPageSource()
author <- html(page_source[[1]]) %>% html_nodes(".user-name") %>% html_text()
text <- html(page_source[[1]]) %>% html_nodes(".comment-text-content") %>% html_text()

#combine the data in a data.frame
dat <- data.frame(author = author, text = text)

Result:
> head(dat)
              author                                                                                       text
1 Kikyo bunny simpie Omg I love fluffy puff she's so adorable when she was dancing on a rainbow it's so cute!!!
2   Tatjana Celinska                                                                                     Ciao 0
3      Yvette Austin                                                                   GET OUT OF MYÂ  HEAD!!!!
4           Susan II                                                                             Watch narhwals
5        Greg Ginger               who in the entire fandom never watched this, should be ashamed,

PFFFTT!!!
6        Arnav Sinha                                                                 LOL what the hell is this?
Comment

PREVIOUS NEXT
Code Example
Typescript :: How to store and mix types in an Array in typescript 
Typescript :: Associate of Arts in Broadcast Media Arts 
Typescript :: two main types of mixtures 
Typescript :: A tuple type element list cannot be empty. 
Typescript :: how to check string array is sorted or not in typescript 
Typescript :: kotlin version that is used for building with gradle 
Typescript :: when should you stop testing 
Typescript :: does i5 7th generation processor supports windows 11 
Typescript :: conditional rendering react typescript 
Typescript :: create a 4x2 integer array and print its attributes 
Typescript :: function which calculates the number of tweets that were posted per day. 
Typescript :: gdscript remove deleted objects from array 
Typescript :: response 404 requests python compare 
Typescript :: inherit with filter typescript 
Typescript :: how do you check ewhich version of typescript you are using 
Typescript :: create n sublists python 
Typescript :: No fragments found in the stream for the streaming request in kinesis livestreaming 
Typescript :: constraints in database 
Typescript :: isolate digits in large number cpp 
Typescript :: reverse a string if its value its greater than 3 
Typescript :: apply function to all elements with a class name 
Typescript :: nest js decorator 
Typescript :: consisting either of digits only or Latin letters 
Typescript :: create seperate file for requests react 
Typescript :: Implement a function that counts the number of nodes in a circularly linked list 
Typescript :: typescript Empty Types 
Typescript :: how to read web page in type script 
Typescript :: tkinter widgets overview 
Typescript :: typescript enum get key by value 
Typescript :: typescript import variable from another file 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =