首页 > 数据库 > > R语言爬虫断点续传解法
来自Hadley Wicham的Advanced R中的异常处理章节,是进行异常处理的方法。针对爬虫掉线问题我设计的一段代码,如果爬取失败睡2秒继续爬。供自己参考。
##############################
is.error = function(x) inherits(x,"try-error") #it can catch an error but still run the codes
#usually put the below codes in a loop
repeat
{
try({
#the parsing codes
},silent=T) -> web
ifelse(is.error(web),Sys.sleep(2),break)
}
#############################
原文作者:;如有侵权,请联系管理员删除。