使用phantomjs更改RSelenium中的下载目录

时间:2017-05-03 19:42:35

标签: selenium phantomjs plotly rselenium

我想从R中的情节下载一个webgl图形.Plotly通过提供一个" export"它允许(R)Selenium参数。当使用chrome作为浏览器时,一切都按预期工作(参见下面的示例1)

library(plotly)
library(magrittr)
library(RSelenium)

p <- plot_ly(z = ~volcano) %>% add_surface()

### Example 1: Chrome (working as expecteded) ###
eCaps <- list(
  chromeOptions = 
    list(prefs = list(
      "profile.default_content_settings.popups" = 0L,
      "download.prompt_for_download" = FALSE,
      "download.default_directory" = getwd()
    )
    )
)

chrome <- rsDriver(port = 4590L, browser = "chrome", 
                geckover = NULL, iedrver = NULL, phantomver = NULL, 
                extraCapabilities = eCaps)
export(p, file = "test1.svg", selenium = chrome)
chrome[["server"]]$stop() 

但是,因为我对一个&#34;沉默&#34;感兴趣在后台下载(没有打开浏览器窗口)我尝试使用phantomjs。这似乎也有效,但将绘图下载到我的默认下载目录(参见下面的示例2)。在我的调查过程中,我遇到了几个老帖子,说在phantomjs中下载文件是不可能的。但由于它似乎可能(但使用默认目录),我认为可能有一种方法同时设置下载目录。

library(plotly)
library(magrittr)
library(RSelenium)

p <- plot_ly(z = ~volcano) %>% add_surface()

### Example 2: Phantom JS (Download path not settable) ###
phjs <- rsDriver(port = 4595L, browser = "phantomjs", 
               chromever = NULL, geckover = NULL, iedrver = NULL)
export(p, file = "test2.svg", selenium = phjs)
phjs[["server"]]$stop() 

简而言之:如何更改phantomjs中的下载文件夹(与(R)selenium一起使用时)?

0 个答案:

没有答案