gpt4 book ai didi

r - 使用 RCurl 在 R 向量中获取网站目录列表

转载 作者:行者123 更新时间:2023-12-04 18:44:50 24 4
gpt4 key购买 nike

我正在尝试获取网站目录中的文件列表。有没有办法做到类似于本地目录列表的 dir() 或 list.files() 命令?我可以使用 RCurl 连接到网站(我需要它,因为我需要通过 HTTPS 的 SSL 连接):

library(RCurl)    
text=getURL(*some https website*
,ssl.verifypeer = FALSE
,dirlistonly = TRUE)

但这会创建一个 HTML 文件,其中包含文件列表的图像、超链接等,但我只需要一个 R 文件向量,就像使用 dir() 获得的文件一样。这可能吗?或者我是否必须进行 HTML 解析才能提取文件名?听起来像一个简单问题的复杂方法。

谢谢,

编辑:如果你可以让它与 http://hgdownload.cse.ucsc.edu/goldenPath/hg19/encodeDCC/wgEncodeGencodeV7/ 一起工作然后你就会明白我的意思。

最佳答案

这是 getURL 帮助文件中的最后一个示例(带有更新的 URL):

url <- 'ftp://speedtest.tele2.net/'
filenames = getURL(url, ftp.use.epsv = FALSE, dirlistonly = TRUE)


# Deal with newlines as \n or \r\n. (BDR)
# Or alternatively, instruct libcurl to change \n’s to \r\n’s for us with crlf = TRUE
# filenames = getURL(url, ftp.use.epsv = FALSE, ftplistonly = TRUE, crlf = TRUE)
filenames = paste(url, strsplit(filenames, "\r*\n")[[1]], sep = "")

这能解决你的问题吗?

关于r - 使用 RCurl 在 R 向量中获取网站目录列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16699856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com