无法使用RSelenium保存屏幕截图

时间:2018-02-23 09:48:50

标签: r selenium selenium-chromedriver

我正在尝试访问http://www.google.com并使用RSelenium获取其屏幕截图。包安装和网站访问的代码如下。

devtools::install_github('ropensci/RSelenium')
install.packages('wdman')

library(RSelenium)

library(wdman)
cDrv <- chrome()
eCaps <- list(chromeOptions = list(
  args = c('--headless', '--disable-gpu', '--window-size=1280,800')
))
remDr<- remoteDriver(browserName = "chrome", port = 4567L, 
                     extraCapabilities = eCaps)
remDr$open()
remDr$navigate("http://www.google.com")
remDr$screenshot(display = TRUE,file = 'test.png')

# clean up
remDr$close()
cDrv$stop()

此次运行的会话信息如下。

R version 3.4.0 (2017-04-21)
    Platform: x86_64-apple-darwin15.6.0 (64-bit)
    Running under: OS X El Capitan 10.11.6

    Matrix products: default
    BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
    LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

    locale:
    [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

    attached base packages:
    [1] stats     graphics  grDevices utils     datasets  methods   base     

    other attached packages:
    [1] wdman_0.2.2     RSelenium_1.7.3

    loaded via a namespace (and not attached):
     [1] Rcpp_0.12.14     XML_3.98-1.10    binman_0.1.0     withr_2.0.0      digest_0.6.14    assertthat_0.2.0
     [7] rappdirs_0.3.1   bitops_1.0-6     R6_2.2.2         jsonlite_1.5     semver_0.2.0     httr_1.3.1      
    [13] curl_2.8.1       xml2_1.1.1       devtools_1.13.3  subprocess_0.8.0 tools_3.4.0      yaml_2.1.14     
    [19] compiler_3.4.0   caTools_1.17.1   memoise_1.1.0    openssl_1.0 

如果我的假设错了,请纠正我。 Chrome驱动程序访问网站,捕获屏幕截图并将其存储在test.png中。这里的问题是,代码运行成功,但我找不到test.png。还有什么我应该做的吗?提前感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

仅在test.png中删除display = TRUE后才能获得remDr$screenshot

remDr$screenshot(file = 'test.png')

希望它可以帮到你。