您可能需要设定一个明确的超时较慢的连接:
library(httr)
library(rvest)
pg <- GET("https://inciweb.nwcg.gov/", timeout(60))
incidents <- html_table(content(pg))[[1]]
str(incidents)
## 'data.frame': 10 obs. of 7 variables:
## $ Incident: chr "Highline Fire" "Cottonwood Fire" "Rattlesnake Point Fire" "Coolwater Complex" ...
## $ Type : chr "Wildfire" "Wildfire" "Wildfire" "Wildfire" ...
## $ Unit : chr "Payette National Forest" "Elko District Office" "Nez Perce - Clearwater National Forests" "Nez Perce - Clearwater National Forests" ...
## $ State : chr "Idaho, USA" "Nevada, USA" "Idaho, USA" "Idaho, USA" ...
## $ Status : chr "Active" "Active" "Active" "Active" ...
## $ Acres : chr "83,630" "1,500" "4,843" "2,969" ...
## $ Updated : chr "1 min. ago" "1 min. ago" "3 min. ago" "5 min. ago" ...
临时的解决方法
l <- charToRaw(paste0(readLines("https://inciweb.nwcg.gov/"), collapse="\n"))
pg <- read_html(l)
html_table(pg)[[1]]
嗯,尝试与不同的超时(#),但不断收到这:'pg < - GET(“https://inciweb.nwcg.gov/”,timeout(60)) curl :: curl_fetch_memory(url,handle = handle)的错误: 达到超时:10000毫秒后连接超时# – S31
是的。我也尝试过R中的其他网站,但遇到同样的问题。通过浏览器访问这些网站正常工作 – S31
是的。使用Windows 7 – S31