-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrselenium_example.R
59 lines (42 loc) · 1.29 KB
/
rselenium_example.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
48
49
50
51
52
53
54
55
56
57
58
59
library(seleniumPipes)
library(RSelenium)
library(rvest)
# https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-docker.html
system("docker pull selenium/standalone-chrome-debug:3.5.0")
system("docker run -d -p 4445:4444 -p 5901:5900 --name chrome_selenium selenium/standalone-chrome-debug:3.5.0")
remDr <- remoteDr(port = 4445L, browserName = "chrome")
remDr %>% setWindowSizeOld(1350, 980)
# Go to google
remDr %>%
go(url = "http://www.google.at") %>%
takeScreenshot
# Search for "r summer school vorau"
remDr %>%
findElement("name", "q") %>%
elementSendKeys("r summer school vorau", key = "enter")
# Go to the Summer School Page
remDr %>%
findElement("css selector", "#ires #rso link+ div a") %>%
elementClick
remDr %>% seleniumPipes::back()
remDr %>% forward()
remDr %>% refresh()
remDr %>% takeScreenshot
# Showcase JS loading
song_url <- "https://www.youtube.com/watch?v=LUlZ5n0cyak"
browseURL(song_url)
remDr %>%
go(url = song_url)
remDr %>%
executeScriptOld("scroll(0, 250);")
remDr %>%
getPageSource %>%
html_node("#content-text") %>%
html_text
read_html(song_url) %>%
html_node("#content-text") %>%
html_text
remDr %>% deleteSession
system("docker stop chrome_selenium")
sleep(5) # give docker some time
system("docker rm chrome_selenium")