-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRSele.R
47 lines (25 loc) · 1.23 KB
/
RSele.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
install.packages("RSelenium")
library("RSelenium")
# important because it downloads all the things(geckodriver,chrome driver,phantom js)
remDr<-rsDriver(port = 4444L,browser = "chrome",version = "latest",chromever = "latest",geckover = "latest",check = TRUE)
Client<-remDr$client
#list of different handles which you want to extract
setwd("D:/UIC/MyResearch")
for(i in 1:nrow(namesUnique)){
Client$open()
#different handles
Client$navigate(paste0("https://www.twitter.com/",gsub("@",replacement = "",x = namesUnique[i,1])))
# escape is required to dismiss the login alert
Client$sendKeysToActiveElement(list(key="escape"))
# 40 is taken because most of the handles in this data frame requires less than 40 "end" keystrokes to reach the first tweet
for(j in 1:40)
{
# required for getting tweets from the page which are not loaded
Client$sendKeysToActiveElement(list(key = "end"))
Css<-Client$findElements(using = "css selector",value = ".tweet-text")
}
CSS_DATA_FRAME<- unlist(lapply(Css, function(x){x$getElementText()}))
CSS_DATA_FRAME<-as.data.frame(CSS_DATA_FRAME)
Client$close()
write.csv(x = CSS_DATA_FRAME,file = paste0(gsub("@",replacement="",x=namesUnique[i,1]),".csv"))
}