Hello Folks
I would like to create a forloop to scrap (with Rvest) H1 tag for a list of urls.
I tried to do it with the following code but it doesn't work.
Does somebody can help me ?
Thanks !
library(rvest)
library(readr)
library(tidyverse)
library(XML)
library(httr)
#URLs list loading
urls <- c("https://www.20minutes.fr/dossier/coronavirus","https://www.20minutes.fr/economie/")
#I create an emplty list
tbl <- list()
#I start forloop
for (i in 1:length(urls)) {
tbl[[i]] <- urls[[i]] %>% # tbl[[i]] assigns each H1 from urls as an element in the tbl list
read_html() %>%
html_nodes("h1") %>%
html_text() %>%
if (dim(tbl)[i] == 0){
i = i+1
}}
tbl
Error message in Console
Error in if (.) dim(tbl)[i] == 0 else { :
the argument cannot be interpreted as a logical value