ITPub博客

首页 > 数据库 > > R语言爬虫断点续传解法

R语言爬虫断点续传解法

作者:浪花小雨滴 时间:2019-06-03 22:27:34 0 删除 编辑

来自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)
}
#############################

原文作者:;如有侵权,请联系管理员删除。

请登录后发表评论 登录
全部评论

注册时间:2018-05-16

  • 博文量
    4259
  • 访问量
    39920