我有这个代码:
library(rvest)
url_list <- c("https://github.com/rails/rails/pull/100",
"https://github.com/rails/rails/pull/200",
"https://github.com/rails/rails/pull/300")
mine <- function(url){
url_content <- html(url)
url_mainnode <- html_node(url_content, "*")
url_mainnode_text <- html_text(url_mainnode)
url_mainnode_text <- gsub("\n", "", url_mainnode_text) # clean up the text
url_mainnode_text
}
messages <- lapply(url_list, mine)
然而,当我把列表加长时,我往往会遇到
Error in html.response(r, encoding = encoding) :
server error: (500) Internal Server Error
我知道在 Ruby 中,我可以使用它rescue来继续遍历列表,即使应用函数的一些尝试失败了。R中有类似的东西吗?