r - 从网站以纯文本/文本格式下载 CSV
问题描述
我正在尝试自动从网站下载数据集,但无法获得我想要的东西。我尝试过使用RCurl
,但它遇到了tlsv1 alert protocol version
错误。我可以使用 执行下载httr
,但我收到的是普通/html 格式的文件,这显然不是我想要的。我已经尝试了一些其他的东西,但似乎没有任何效果。请指教。
下载代码httr
:
###lung cancer screening locator tool url
url1 = "https://report.acr.org/#/site/PUBLIC/views/NRDRLCSLocator/ADownload.csv"
GET(url1, write_disk(tf <- tempfile(fileext = ".csv"))) #produces file of content type 'plain/html'
lcsr = read.csv(tf)
此请求的原始网站是https://www.acr.org/Clinical-Resources/Lung-Cancer-Screening-Resources/LCS-Locator-Tool,其背后的 Tableau 位于https://report.acr。 org/t/PUBLIC/views/NRDRLCSLocator/LCSLocator?:embed=y&:showVizHome=no&:host_url=https%3A%2F%2Freport.acr.org%2F&:embed_code_version=3&:tabs=no&:toolbar=no&:showAppBanner =no&:display_spinner=no&:loadOrderID=0
解决方案
一个RSelenium
解决方案,
按此设置下载目录,
library(RSelenium)
#Setting download directory,
eCaps <- list(
chromeOptions =
list(prefs = list('download.default_directory' = "D:\\mywork"))
)
driver <- rsDriver(browser = "chrome", extraCapabilities = eCaps)
remDr <- driver[["client"]]
remDr$navigate("https://report.acr.org/#/site/PUBLIC/views/NRDRLCSLocator/ADownload.csv")
library(readr)
df = read_csv('ADownload.csv')
推荐阅读
- excel - DAX 公式 - 期初余额月刊
- windows - Docker:获取,组件 CommunityInstaller.AutoStartAction 失败:尝试执行未经授权的操作
- firebase - 选择时如何自动显示图像(颤动)
- javascript - TypeError: (0 , _style.default) 不是函数 - jest + material-ui
- sql - SQL Query 简化,真的很慢查询 1-2 分钟
- extjs - Extjs 中的模型如何仅从对返回具有多个节点的 json 的服务的调用中读取一个字段?
- freeradius - 在 FreeRADIUS 中,具有不同的接口、不同的端口?
- javascript - reactjs无法使用querySelector获取ID-ID值是从数据reactjs生成的
- r - 删除 r 中不包含 x 的列
- php - 无法使用漂亮的 .htaccess URL 部署 PHP 项目