Using R to get download URL by link name

前端 未结 2 1065
灰色年华
灰色年华 2021-01-27 18:00

I\'m trying to use rvest to download a list of files from this site. The file names are regular, but the download URLs don\'t match a pattern (just dozens of digits

2条回答
  •  不要未来只要你来
    2021-01-27 18:48

    How about using map2 from purrr to combine two vectors all and html_attr(html_nodes(doc, "a"), "href") and then filter according to file type names

     url <- "http://www-air.larc.nasa.gov/cgi-bin/ArcView/actamerica.2016?C130=1"
    doc <- read_html(url)
    all <- html_text(html_nodes(doc, "td a"))
    href <- html_attr(html_nodes(doc, "a"), "href")
    
    z <- purrr::map2(all, href, function(x, y) data.frame(x, y)) 
    z <- do.call(rbind, z)
    filetype <- "PICARRO"
    z[grep(filetype, z[,1]),]
    

提交回复
热议问题