-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_css1.R
49 lines (42 loc) · 1.21 KB
/
ex_css1.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
if(!require(dplyr)) {
install.packages("dplyr", repos="http://cran.us.r-project.org")
require(dplyr)
}
if(!require(rvest)) {
install.packages("rvest", repos="http://cran.us.r-project.org")
require(rvest)
}
if(!require(httr)) {
install.packages("httr", repos="http://cran.us.r-project.org")
require(httr)
}
if(!require(purrr)) {
install.packages("purrr", repos="http://cran.us.r-project.org")
require(purrr)
}
if(!require(jsonlite)) {
install.packages("jsonlite", repos="http://cran.us.r-project.org")
require(jsonlite)
}
base_url <- 'https://zi-training.zi.uzh.ch/de/page/courseprogramme'
# extract the url of the title
read_html(base_url) %>%
html_element('.headernav_title a') %>%
html_attr('href')
# get all urls of the top navigation
read_html(base_url) %>%
html_elements('.headernav_elements') %>%
html_elements('a') %>%
html_attr('href')
# get the urls of both of them
read_html(base_url) %>%
html_elements('.headernav_title a, .headernav_elements a') %>%
html_attr('href')
# booked courses
read_html(base_url) %>%
html_elements('#kursList .warning a') %>%
html_text()
# second title
read_html(base_url) %>%
html_elements('#kursList tr:nth-child(2) a') %>%
html_text()