R错误HTTP状态为“503服务暂时不可用”'

时间:2017-05-04 08:30:58

标签: r web-scraping

我必须从网站http://www.kase.kz/ru/marketvaluation

下载几个zip文件

这个问题基本上来自this主题。到目前为止还没有解决问题,我尝试了以下方法:

for (i in 1:length(data[,2])){
    URL = data[i, 2]
    dir = basename(URL)
    download.file(URL, dir)
    unzip(dir)
    TXT <- list.files(pattern = "*.TXT")
    zip <- list.files(pattern = "*.zip")
    file.remove(TXT, zip)
}

现在我面临另一个问题 - 在第4或第5次审判后R给了我:

trying URL 'http://www.kase.kz/files/market_valuation/ru/2017/val170403170409.zip'
Error in download.file(URL, dir) : 
  cannot open URL 'http://www.kase.kz/files/market_valuation/ru/2017/val170403170409.zip'
In addition: Warning message:
In download.file(URL, dir) :
  cannot open URL 'http://www.kase.kz/files/market_valuation/ru/2017/val170403170409.zip': HTTP status was '503 Service Temporarily Unavailable'

我不知道为什么会这样。我将不胜感激任何建议/解决方案。

1 个答案:

答案 0 :(得分:1)

啊,这是小菜一碟:

for (i in 1:length(data[,2])){
    URL = data[i, 2]
    dir = basename(URL)
    download.file(URL, dir)
    unzip(dir)
    TXT <- list.files(pattern = "*.TXT")
    zip <- list.files(pattern = "*.zip")
    file.remove(TXT, zip)
    Sys.sleep(sample(10, 1))
}