如何从需要验证的 URL 下载 R 中的文件?
How to download a file in R from a URL that requires a verification?
我正在尝试通过 R 以编程方式下载 Clinical Lab Fee Schedule from Medicare。
library("readxl")
ZIPURL <- "https://www.cms.gov/apps/ama/license.asp?file=/Medicare/Medicare-Fee-for-Service-Payment/ClinicalLabFeeSched/Downloads/18CLAB.zip"
CLAB_FileName <- "CLAB2018v1.xls"
temp <- tempfile()
download.file( ZIPURL,temp, mode="wb")
con <- unzip(temp, CLAB_FileName)
CLAB <- read_excel(CLAB_FileName,skip=1, col_names=TRUE)
unlink(temp)
要下载 ZIP 文件,网站要求用户单击 "Accept" 按钮。此验证步骤似乎会干扰 download.file()
,因此代码会改为下载 html 页面。 R 中是否有绕过或输入验证的选项或额外选项?
我从命令中看到的响应是:
download.file( ZIPURL,temp, mode="wb")
trying URL
'http://www.cms.gov/apps/ama/license.asp?file=/Medicare/Medicare-Fee-for-Service-Payment/ClinicalLabFeeSched/Downloads/18CLAB.zip'
Content type 'text/html' length 42502 bytes (41 KB) downloaded 41 KB
con <- unzip(temp, CLAB_FileName)
Warning message: In unzip(temp, CLAB_FileName) : error 1 in extracting
from zip file
CLAB <- read_excel(CLAB_FileName,skip=1, col_names=TRUE)
Error in read_fun(path = path, sheet = sheet, limits = limits, shim =
shim, : Evaluation error: path1="CLAB2018v1.xls": The system
cannot find the file specified.
我正在尝试通过 R 以编程方式下载 Clinical Lab Fee Schedule from Medicare。
library("readxl")
ZIPURL <- "https://www.cms.gov/apps/ama/license.asp?file=/Medicare/Medicare-Fee-for-Service-Payment/ClinicalLabFeeSched/Downloads/18CLAB.zip"
CLAB_FileName <- "CLAB2018v1.xls"
temp <- tempfile()
download.file( ZIPURL,temp, mode="wb")
con <- unzip(temp, CLAB_FileName)
CLAB <- read_excel(CLAB_FileName,skip=1, col_names=TRUE)
unlink(temp)
要下载 ZIP 文件,网站要求用户单击 "Accept" 按钮。此验证步骤似乎会干扰 download.file()
,因此代码会改为下载 html 页面。 R 中是否有绕过或输入验证的选项或额外选项?
我从命令中看到的响应是:
download.file( ZIPURL,temp, mode="wb")
trying URL 'http://www.cms.gov/apps/ama/license.asp?file=/Medicare/Medicare-Fee-for-Service-Payment/ClinicalLabFeeSched/Downloads/18CLAB.zip' Content type 'text/html' length 42502 bytes (41 KB) downloaded 41 KB
con <- unzip(temp, CLAB_FileName)
Warning message: In unzip(temp, CLAB_FileName) : error 1 in extracting from zip file
CLAB <- read_excel(CLAB_FileName,skip=1, col_names=TRUE)
Error in read_fun(path = path, sheet = sheet, limits = limits, shim = shim, : Evaluation error: path1="CLAB2018v1.xls": The system cannot find the file specified.