-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01-download.r
65 lines (46 loc) · 1.58 KB
/
01-download.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
60
61
62
63
64
65
library(tidyverse)
library(rvest)
fs::dir_create("html/conference-days")
fs::dir_create("html/sessions")
fs::dir_create("html/abstracts")
# no need to collect day 1 (pre-session meetings only)
for (i in str_c("https://coms.events/epsa2021/en/day_", 2:3, ".html")) {
f <- fs::path("html", "conference-days", fs::path_file(i))
cat(f, ": ")
if (!fs::file_exists(f)) {
download.file(i, f, mode = "wb", quiet = TRUE)
}
s <- read_html(f) %>%
html_nodes(xpath = "//a[contains(@href, 'session_')]") %>%
html_attr("href") %>%
str_replace("^\\.\\.", "https://coms.events/epsa2021")
cat(length(s), "sessions\n")
for (j in s) {
f <- fs::path("html", "sessions", fs::path_file(j))
cat(f, ": ")
if (!fs::file_exists(f)) {
download.file(j, f, mode = "wb", quiet = TRUE)
}
a <- read_html(f) %>%
html_nodes(xpath = "//a[contains(@href, 'abstract_')]") %>%
html_attr("href") %>%
str_replace("^\\.\\./\\.\\.", "https://coms.events/epsa2021/data")
cat(length(a), "abstracts")
for (k in a) {
f <- fs::path("html", "abstracts", fs::path_file(k))
if (!fs::file_exists(f)) {
# `try` because of a few malformed URIs (as of 2021-06-22)
# e.g. 'https://coms.events/epsa2021/data/abstracts/en/<abstract_125>'
# in session 35
try(download.file(k, f, mode = "wb", quiet = TRUE), silent = TRUE)
}
cat(".")
}
cat("\n")
}
}
cat(
length(fs::dir_ls("html/sessions", glob = "*.html")), "sessions,",
length(fs::dir_ls("html/abstracts", glob = "*.html")), "abstracts.\n"
)
# kthxbye