When I am trying to run below code I get an error as "Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class ""try-error"" to a data.frame "
I am using try function to skip through the LINKS which are not working and continue with the loop but that's not happening. Can someone help me with this
base_url <- c("https://www.sec.gov/Archives/edgar/data/1409916/000162828017002570/exhibit211nobilishealthcor.htm",
"https://www.sec.gov/Archives/edgar/data/1300317/000119312507128181/dex211.htm",
"https://www.sec.gov/Archives/edgar/data/1453814/000145381417000063/subsidiariesoftheregistran.htm",
"https://www.sec.gov/Archives/edgar/data/25743/000138713117001111/ex21-1.htm",
"https://www.sec.gov/Archives/edgar/data/880631/000119312517065534/d280058dex211.htm",
"https://www.sec.gov/Archives/edgar/data/1058290/000105829017000008/ctshexhibit21112312016.htm",
"https://www.sec.gov/Archives/edgar/data/1031927/000141588916005383/ex21-1.htm",
"https://www.sec.gov/Archives/edgar/data/1358071/000135807118000008/cxoexhibit211.htm",
"https://www.sec.gov/Archives/edgar/data/904979/000090497918000006/exhibit211q4fy17listofsubs.htm",
"https://www.sec.gov/Archives/edgar/data/41296/000094420901500099/dex21.txt",
"https://www.sec.gov/Archives/edgar/data/808461/000080846117000024/gciexhibit21-1123116.htm",
"https://www.sec.gov/Archives/edgar/data/1101026/000107878213000519/f10k123112_ex21.htm",
"https://www.sec.gov/Archives/edgar/data/932372/000141588915000759/ex21-1.htm"
)
df <- lapply(base_url,function(u){
try({
html_obj <- read_html(u)
draft_table <- html_nodes(html_obj,'table')
cik <- substr(u,start = 41,stop = 47)
draft1 <- html_table(draft_table,fill = TRUE)
final <- c(cik,draft1)
},silent = TRUE)
})
require(reshape2)
data <- melt(df)
data <- as.data.frame(data,row.names = NULL)
data <- data[,1:2]
names(data) <- c("CIK","Company")
data2 <- transform(data, CIK = na.locf(CIK ))