SCI <- function(doi) {
library(rvest)
library(stringr)
setwd("D:/360Downloads")
web <- paste0("https://sci-hub.tw/", doi)
web_info <- read_html(web, encoding = "UTF-8")
web_target <- html_nodes(web_info, "#pdf")
mypdf <- html_attr(web_target, name = "src")
download.file(mypdf, "doi.pdf", mode = "wb")
#改名
title <- html_nodes(web_info, "#citation")
TITLE <- html_text(title)
TITLE <- str_replace_all(TITLE, "/", "")
TITLE <- str_replace_all(TITLE, ":", "")
TITLE <- str_replace_all(TITLE, "<", "")
TITLE <- str_replace_all(TITLE, ">", "")
TITLE <- gsub("?", "", TITLE, fixed = TRUE)
TITLE <- str_sub(TITLE, 1, 235)
file.rename("doi.pdf", paste0(TITLE, ".pdf"))
}
SCI("https://doi.org/10.1016/j.aquatox.2016.12.005")
## Loading required package: xml2
## [1] TRUE