【问题标题】:withTimeout not working inside functions?withTimeout 在函数内部不起作用?
【发布时间】:2017-09-07 10:42:50
【问题描述】:

我在使用 R.utils::withTimeout() 时遇到了一些问题。它似乎根本没有考虑超时选项,或者只是有时。在我要使用的功能下方:

scrape_player <- function(url, time){

  raw_html <- tryCatch({
    R.utils::withTimeout({
      RCurl::getURL(url)
    },
    timeout = time, onTimeout = "warning")}
  )

  html_page <- xml2::read_html(raw_html)
}

现在当我使用它时:

scrape_player("http://nhlnumbers.com/player_stats/1", 1)

它要么工作正常,我得到我想要的 html 页面,要么我收到一条错误消息,告诉我已达到经过的时间限制,或者,这是我的问题,它需要很长时间,远远超过1秒,最终返回一个错误500的html页面。

不应该RCurl::getURL() 只尝试 1 秒(在示例中)来获取 html 页面,如果不是,则简单地返回警告?我错过了什么?

【问题讨论】:

    标签: r rvest rcurl


    【解决方案1】:

    好的,我做了一个解决方法:我没有返回页面,而是将其写入磁盘。不能解决 withTimeout 似乎不起作用的问题,但至少我看到我正在将页面写入磁盘,虽然缓慢但确实如此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-07
      相关资源
      最近更新 更多