Skip to content

Instantly share code, notes, and snippets.

@dubsnipe
Created November 11, 2020 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dubsnipe/1b384c44ec1b7bf88f878b28096f3f25 to your computer and use it in GitHub Desktop.
Save dubsnipe/1b384c44ec1b7bf88f878b28096f3f25 to your computer and use it in GitHub Desktop.
Extract title from a list of URLS
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