正在从网站下载 plain/text CSV
Downloading CSV as plain/text from Website
我正在尝试自动从网站下载数据集,但无法获得我想要的内容。我曾尝试使用 RCurl
,但它遇到了 tlsv1 alert protocol version
错误。我可以使用httr
执行下载,但我收到的是plain/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 and the Tableau behind it is located at 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')
我正在尝试自动从网站下载数据集,但无法获得我想要的内容。我曾尝试使用 RCurl
,但它遇到了 tlsv1 alert protocol version
错误。我可以使用httr
执行下载,但我收到的是plain/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 and the Tableau behind it is located at 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')