我正在尝试通过R从安全站点下载png
映像。
为了访问安全站点,我使用了运行良好的Rvest
。
到目前为止,我已经提取了png
图像的URL。
如何使用rvest下载此链接的图像?rvest
函数之外的函数由于没有权限而返回错误。
当前尝试次数
library(rvest)
uastring <- "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
session <- html_session("https://url.png", user_agent(uastring))
form <- html_form(session)[[1]]
form <- set_values(form, username = "***", password="***", cookie_checkbox= TRUE)
session<-submit_form(session, form)
session2<-jump_to(session, "https://url.png")
## Status 200 using rvest, sucessfully accsessed page.
session
<session> https://url.png
Status: 200
Type: image/png
Size: 438935
## Using download.file returns status 403, page unable to open.
download.file("https://url.png", destfile = "t.png")
cannot open: HTTP status was '403 Forbidden'
在url上尝试了readPNG
和download.file
,由于没有从经过身份验证的安全站点下载的权限,这两个都失败了(错误:403),这就是为什么我首先使用rvest。
3条答案
按热度按时间r55awzrz1#
下面是一个将R徽标下载到当前目录的示例。
编辑
由于涉及到身份验证,因此肯定需要Austin提出的使用会话的建议。试试这个:
8yoxcaq72#
试试下面的例子:
你现在有“测试。jpg”即图片:
rqcrx0a63#
处理多个查询,重命名文件,并在Txt文件中注册链接。对于带有空格的查询,请在中间使用+,请参见示例中的。