-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_springer_books_script.Rmd
53 lines (36 loc) · 1.12 KB
/
read_springer_books_script.Rmd
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
---
title: "books"
author: "Sarah Van Alsten"
date: "4/27/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(pdftools)
library(readxl)
library(httr)
library(janitor)
library(XML)
```
```{r}
books <- readxl::read_xlsx('Springer.xlsx')
books <- janitor::clean_names(books)
print('Download started.')
for (i in 1:nrow(books)){
r <- httr::GET(books$open_url[i])
new_url <- r$url
new_url <- stringr::str_replace(new_url, '/book/','/content/pdf/') %>%
stringr::str_replace('%2F','/') %>% paste0('.pdf')
final <- stringr::str_split(new_url, '/')[-1]
final <- stringr::str_replace(books$book_title[i], ',','-') %>%
stringr::str_replace('.','') %>% stringr::str_replace('/',' ') %>%
paste0("_")
final2 <- stringr::str_replace(books$author[i],', ','+') %>%
stringr::str_replace('.','') %>% stringr::str_replace('/',' ') %>%
paste0('.pdf')
final3 <- paste0(final, final2)
download.file(new_url, final3, mode="wb")
}
print('Download finished.')
```