这对我有用:
getIt = function(what,when){
url=paste0("http://oilandgas.ky.gov/Production%20Reports%20Library/",
when,"%20-%20",what,
"%20Production.xls")
destfile=paste0("/tmp/",what,when,".xls")
download.file(url,destfile)
}
例如:
> getIt("gas",2006)
trying URL 'http://oilandgas.ky.gov/Production%20Reports%20Library/2006%20-%20gas%20Production.xls'
Content type 'application/vnd.ms-excel' length 3490304 bytes (3.3 Mb)
opened URL
==================================================
downloaded 3.3 Mb
第一个除外:
> getIt("oil",2010)
trying URL 'http://oilandgas.ky.gov/Production%20Reports%20Library/2010%20-%20oil%20Production.xls'
Error in download.file(url, destfile) :
cannot open URL 'http://oilandgas.ky.gov/Production%20Reports%20Library/2010%20-%20oil%20Production.xls'
In addition: Warning message:
In download.file(url, destfile) :
cannot open: HTTP status was '404 NOT FOUND'
虽然我可以得到 2010 年的汽油数据:
> getIt("gas",2010)
trying URL 'http://oilandgas.ky.gov/Production%20Reports%20Library/2010%20-%20gas%20Production.xls'
Content type 'application/vnd.ms-excel' length 4177408 bytes (4.0 Mb)
opened URL
==================================================
downloaded 4.0 Mb
所以看起来他们改变了那个链接的系统。您可以通过以下链接获取该数据,然后在粗糙的 Sharepoint HTML 中查找下载链接。
这就是我们讨厌 Sharepoint 的原因,孩子们。