R: Download image using rvest

前端 未结 2 1548
南旧
南旧 2020-12-15 00:12

I\'m attempting to download a png image from a secure site through R.

To access the secure site I used Rvest which worked well.

So

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 00:36

    Try this example below:

    library(rvest); library(dplyr)
    
    url <- "http://www.calacademy.org/explore-science/new-discoveries-an-alaskan-butterfly-a-spider-physicist-and-more"
    webpage <- html_session(url)
    link.titles <- webpage %>% html_nodes("img")
    
    img.url <- link.titles[13] %>% html_attr("src")
    
    download.file(img.url, "test.jpg", mode = "wb")
    

    You now have "test.jpg" which is the picture:

提交回复
热议问题