使用 RSelenium 下载 pdf [英] Downloading a pdf using RSelenium
问题描述
我试图用 RSelenium
包做的是,
What I am trying to do with RSelenium
package is,
步骤:1 访问网站 - 我自己的电力供应商
Step:1 Access a website - My own electric utility provider
步骤:2 通过明确提供我的用户名和密码来访问我的帐户(这就是我无法共享代码的原因)
Step:2 Access my account by explicitly providing my username and password (That's the reason I am unable to share the code)
步骤:3 我点击'查看我的帐单'.帐单以 pdf 格式显示.
Step:3 I click 'VIEW MY BILL'. The bill is displayed in pdf format.
有没有办法下载该文件并保存到特定文件夹?当我使用 download.file()
命令时,它不会保存文档,而是得到一个无法打开的 3KB pdf 文件.Adobe Reader 说读取文档时出错.
Is there a way to download that file and save to specific folder?
When I used download.file()
command, it does not save the document, rather I get a 3KB pdf file that I am not able to open. Adobe Reader says that there is an error reading the document.
我尝试过的可能方法:1. 右键单击,按四次向下箭头,然后转到 'SAVE PAGE AS' 单击 Enter.
Possible method that I tried: 1. Right clicking, Pressing down arrow four times and then get to 'SAVE PAGE AS' click Enter.
但随后它会弹出一个对话框,询问文件名和位置,我无法通过 RSelenium 输入这些详细信息并保存文件.
But then it pops a dialog box asking for file name and location and I am not able to enter those details via RSelenium and save the file.
示例代码:在网上找到的一些随机 PDF.
Example code: Some random PDF found online.
url<- "http://www.immigrationpolicy.org/sites/default/files/docs/how_us_immig_system_works.pdf"
setwd("C:/Users/king/Desktop/bill")
library(RSelenium)
library(downloader)
checkForServer()
startServer()
remDr <- remoteDriver()
remDr$open()
remDr$navigate(url)
推荐答案
我在不断的研究中找到了答案.
I found the answer on continuous research.
首先检查是否安装了Rtools(使用此链接找到答案)
Firstly check whether Rtools is installed (Found the answer using this link)
然后更新我的程序
cprof<-makeFirefoxProfile(list(
"pdfjs.disabled"=TRUE,
"plugin.scan.plid.all" = FALSE,
"plugin.scan.Acrobat" = "99.0",
"browser.helperApps.neverAsk.saveToDisk"='application/pdf',
))
remDr <- remoteDriver(extraCapabilities=cprof)
仍在尝试更改我尚未找到的下载文件夹.我从 中找到了答案这个链接
Trying still to change the download folder which I am not able to find yet. I found the answer from THIS link
这篇关于使用 RSelenium 下载 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!