【发布时间】:2017-10-10 18:15:07
【问题描述】:
我正在尝试使用rvest 从this site. 下载文件列表文件名是常规的,但下载 URL 不匹配模式(只有几十位数字),所以我不能根据任何标准构建下载 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")
提前感谢您的帮助。
【问题讨论】:
标签: html css r web-scraping