R 检查html是否可用

R 检查html是否可用,r,R,我想知道如何检查html是否可用。如果不是,我希望控制返回以避免因错误而停止脚本。 例: 努夫说 另一种选择是try()——它比trycatch()更容易使用,但没有那么好用。您可能还需要抑制警告,因为R将报告无法解析地址 您希望在脚本中包含以下内容: URL <- "http://www.pageerror.com.br" arq <- try(suppressWarnings(readLines(con <- url(URL))), silent = TRUE) close

我想知道如何检查html是否可用。如果不是,我希望控制返回以避免因错误而停止脚本。 例:


努夫说 另一种选择是
try()
——它比
trycatch()
更容易使用,但没有那么好用。您可能还需要抑制警告,因为R将报告无法解析地址

您希望在脚本中包含以下内容:

URL <- "http://www.pageerror.com.br"
arq <- try(suppressWarnings(readLines(con <- url(URL))), silent = TRUE)
close(con) ## close the connection
if(inherits(arq, "try-error")) {
    writeLines(strwrap(paste("Page", URL, "is not available")))
} else {
    print(arq)
}

URL-1绝对不是“努夫说的”,因为
?trycatch
不返回任何信息,使用
trycatch
并不容易-举个例子会有帮助。@Abe--这就是
?trycatch
输出底部的文本的目的。
?trycatch
的底部仍然留给我(显然还有很多其他人)寻找答案等等。
URL <- "http://www.pageerror.com.br"
arq <- try(suppressWarnings(readLines(con <- url(URL))), silent = TRUE)
close(con) ## close the connection
if(inherits(arq, "try-error")) {
    writeLines(strwrap(paste("Page", URL, "is not available")))
} else {
    print(arq)
}