R:无法从安全站点下载PNG图像

时间:2016-03-21 20:58:36

标签: r https web-scraping rcurl httr

我正在尝试从HTTPS的网址下载PNG图片,需要logincookies

从我的浏览器中尝试我可以轻松下载图像。

但是,我在R

中返回以下错误
download.file(URL, dest = "test.png")

trying URL 'https://url.png'
Error in download.file(URL, dest = "test.png") : 
  cannot open URL 'https://url.png'
In addition: Warning message:
In download.file(URL, dest = "test.png") :
  cannot open: HTTP status was '403 Forbidden'

请注意,出于隐私问题而忽略了实际网址

我尝试使用httrRCurl没有太多运气。

尝试

## Provided `user/pass` as well as `user_agent` so site thinks i'm a browser, not robot
library(httr)    
url <- "https://url.png"
html <- GET(url, authenticate("user", "pass"), user_agent("Mozilla/5.0"))
html

Response [https://url.png]
  Date: 2016-03-22 11:46
  Status: 403
  Content-Type: text/html; charset=UTF-8
  Size: 4.18 kB

0 个答案:

没有答案