-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_css2.R
35 lines (31 loc) · 1.18 KB
/
demo_css2.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
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://www.uzh.ch/cmsssl/en/studies/dates/dates.html'
# reading one specific table
read_html(base_url) %>%
# use the direct sibling combinator to extract a table contained within a div next to the element with id #Fall_Semester_2021
html_element('#Fall_Semester_2021 + div table') %>%
html_table()
# the following doesn't work, because table is not a direct descendant of the div that is a sibling of #Fall_Semester_2021
read_html(base_url) %>%
# use the direct sibling combinator to extract a table contained within a div next to the element with id #Fall_Semester_2021
html_element('#Fall_Semester_2021 + div > table') %>%
html_table()