I'd like to take some informations from a list of website. I have a list of urls, but there are some that doesn't work/exesist.
The Error is:
Error in open.connection(x, "rb") : HTTP error 404 R
library(Rvest)
url_web<-(c("https://it.wikipedia.org/wiki/Roma",
"https://it.wikipedia.org/wiki/Milano",
"https://it.wikipedia.org/wiki/Napoli",
"https://it.wikipedia.org/wiki/Torinoooo", # for example this is an error
"https://it.wikipedia.org/wiki/Palermo",
"https://it.wikipedia.org/wiki/Venezia"))
I write this code for my target.
I tried to use try
, but doesn't work.
I tried to use an ifelse(url.exists(url_web)==TRUE,Cont<-read_html(url_web), NA )
into the for
, but doesn't work.
for (i in 1:length(url_web)){
Cont<-read_html(i)
Dist_1<-html_nodes(Cont, ".firstHeading") %>%
html_text()
print(Dist_1)
}
The question is: How I can jump the url where I can't link or where is writes wrong?
Thank you in advance.
Francesco