Created
November 11, 2020 04:09
-
-
Save dubsnipe/1b384c44ec1b7bf88f878b28096f3f25 to your computer and use it in GitHub Desktop.
Extract title from a list of URLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(tidyverse) | |
require(rvest) | |
toolbox <- tibble(read.csv("toolbox.csv", header=T)) | |
read_title <- function(x){ | |
tmp <- read_html(x) %>% html_node("title") %>% html_text() | |
return(tmp) | |
} | |
titles <- vector() | |
for (i in 1:length(toolbox$url)){ | |
tryCatch({ | |
title_test <- read_title(toolbox$url[i]) | |
titles[i] <- title_test | |
}, warning = function(w){ | |
return(NA) | |
}, | |
error = function(e) { | |
return(NA) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment