我正在尝试从HTTPS
的网址下载PNG图片,需要login
和cookies
。
从我的浏览器中尝试我可以轻松下载图像。
但是,我在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'
请注意,出于隐私问题而忽略了实际网址
我尝试使用httr
和RCurl
没有太多运气。
## 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