一尘不染

无法执行rsDriver(连接被拒绝)

docker

我不能用Rselenium得到任何好处。这是第一步,也是我的输出:

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.

我错过了什么 ?


阅读 871

收藏
2020-06-17

共1个答案

一尘不染

尝试运行不建议使用的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.

大家似乎 对发生问题rsDriver和码头工人是推荐的选项,所以我们走的这条路:

  • 安装码头工人
  • 运行它,按要求重新启动计算机
  • 通过在命令行中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"

有关更多信息的文档:

2020-06-17