我试图使用rvest
从this site.下载文件列表文件名是固定的,但下载网址与模式(仅数十位数)不匹配,所以我无法根据任何标准构建下载网址列表。我如何使用链接名称下载实际文件?使用R通过链接名称获取下载URL
到目前为止,我可以得到感兴趣的文件列表(基于CSS选择器),并且我可以获得网站上所有链接的列表,但我不知道如何匹配它们。我需要能够检查网站的变化并下载任何名称更改的文件,因此使用文件名访问文件非常重要。我对HTML/CSS不是很熟悉,所以这可能是我无法弄清楚这个可能简单的任务的原因。
library(rvest)
# url with list of download files
url <- "http://www-air.larc.nasa.gov/cgi-bin/ArcView/actamerica.2016?C130=1"
doc <- read_html(url)
# getting everything within the CSS selector "td a"
all <- html_text(html_nodes(doc, "td a"))
# getting list of certain file names
filetype <- "PICARRO"
files <- all[grep(filetype, all)]
# this returns a list of all links on the page,
# but I'm not sure how to match the links up with their names
html_attr(html_nodes(doc, "a"), "href")
非常感谢您的帮助。