Downloading a pdf using RSelenium

给你一囗甜甜゛ 提交于 2019-11-29 15:50:00

问题


What I am trying to do with RSelenium package is,

Step:1 Access a website - My own electric utility provider

Step:2 Access my account by explicitly providing my username and password (That's the reason I am unable to share the code)

Step:3 I click 'VIEW MY BILL'. The bill is displayed in pdf format.

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.

Possible method that I tried: 1. Right clicking, Pressing down arrow four times and then get to 'SAVE PAGE AS' click Enter.

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.

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)

回答1:


I found the answer on continuous research.

Firstly check whether Rtools is installed (Found the answer using this link)

Then updated my program

`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



来源:https://stackoverflow.com/questions/34476422/downloading-a-pdf-using-rselenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!