无法执行rsDriver(拒绝连接)

时间:2017-07-30 02:38:57

标签: r docker rselenium

我无法获得R selenium。这是第一步和我的输出:

library(RSelenium)
rD <- rsDriver()
# checking Selenium Server versions:
#   BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking chromedriver versions:
#   BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking geckodriver versions:
#   BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# checking phantomjs versions:
#   BEGIN: PREDOWNLOAD
# BEGIN: DOWNLOAD
# BEGIN: POSTDOWNLOAD
# [1] "Connecting to remote server"
# Error in checkError(res) : 
#   Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused
# In addition: Warning message:
#   In rsDriver() : Could not determine server status.

我错过了什么?

3 个答案:

答案 0 :(得分:17)

尝试运行已弃用的checkForServer()时,Selenium提供了两个选项:

  • 使用rsDriver
  • 使用Docker

请参阅:

RSelenium::checkForServer()
# Error: checkForServer is now defunct. Users in future can find the function in 
# file.path(find.package("RSelenium"), "examples/serverUtils"). The
# recommended way to run a selenium server is via Docker. Alternatively
# see the RSelenium::rsDriver function.

Everybody seems to与rsDriver存在问题,推荐使用Docker,因此我们将采用以下方式:

  • install docker
  • 运行它,按要求重新启动计算机
  • 通过在命令行中运行来提取图片:docker pull selenium/standalone-firefox(或chrome代替firefox)或R shell('docker pull selenium/standalone-firefox')
  • 通过在命令行中运行来启动服务器:docker run -d -p 4445:4444 selenium/standalone-firefox或在R shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
  • 然后运行remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox'")。该文档提出了与虚拟机不同的东西,但我无法让它工作。

有了这个我设置,这是我的代码:

shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox")
remDr$open()
remDr$navigate("http://www.google.com/ncr")
remDr$getTitle()
# [[1]]
# [1] "Google" 

更多信息的文档:

答案 1 :(得分:1)

在仍然有用的情况下,我今天遇到了同样的问题,并且能够通过安装Java开发工具包(Java SE开发工具包11.0.1)来解决它。

我从计算机上收到了一条错误消息,说明该问题以及与该问题相同的R错误,并已将其修复。

对于一个可复制的示例,我能够复制此tutorial

  

sessionInfo()       R版本3.4.4(2018-03-15)       平台:x86_64-apple-darwin15.6.0(64位)       运行在:macOS High Sierra 10.13.5

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] fr_CA.UTF-8/fr_CA.UTF-8/fr_CA.UTF-8/C/fr_CA.UTF-8/fr_CA.UTF-8

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

other attached packages:
[1] RSelenium_1.7.5

loaded via a namespace (and not attached):
[1] Rcpp_0.12.17     XML_3.98-1.11    binman_0.1.1     assertthat_0.2.0 rappdirs_0.3.1   bitops_1.0-6    
[7] R6_2.2.2         jsonlite_1.5     semver_0.2.0     httr_1.3.1       curl_3.2         xml2_1.2.0      
[13] subprocess_0.8.3 tools_3.4.4      wdman_0.2.4      yaml_2.1.18      compiler_3.4.4   caTools_1.17.1  
[19] openssl_1.0.1 

答案 2 :(得分:1)

我必须运行Cran小插图:

shell(“ docker-machine ip”)

然后将remoteServerAddr设置为返回的IP。