无法执行rsDriver(连接被拒绝) [英] can't execute rsDriver (connection refused)

查看:179
本文介绍了无法执行rsDriver(连接被拒绝)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能用R硒去任何地方。这是第一步,也是我的输出:

I can't get anywhere with R selenium. Here's the first step and my output:

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.

我错过了什么?

推荐答案

注意:此答案适用于Windows

在尝试运行已弃用的 checkForServer()时 Selenium提供了两种选择:

When trying to run the deprecated checkForServer() Selenium offers two options:


  • 使用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.

每个人 似乎 < a href = https://stackoverflow.com/questions/45293675/rselenium-rsdriver-peer-ssl-certificate-issue?s=3%7C2.7177>要与rsDriver有关,而Docker是推荐的选项,因此我们将采用以下路线:

Everybody seems to have issues with rsDriver and Docker is the recommended option so we'll go this route:


  • 安装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 =本地主机,端口= 4445L,浏览器名称= firefox)。该文档对虚拟机提出了一些不同的建议,但我无法使其正常工作。

  • install docker
  • run it, restart computer as requested
  • pull image by running in command line: docker pull selenium/standalone-firefox(or chrome instead of firefox) or in R shell('docker pull selenium/standalone-firefox')
  • start server by running in command line: docker run -d -p 4445:4444 selenium/standalone-firefox or in R shell('docker run -d -p 4445:4444 selenium/standalone-firefox')
  • Then run remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4445L, browserName = "firefox'") . The doc suggests something different with a virtual machine but i couldn't get it to work.

为此,我设置了以下代码:

With this I was set, here is my code:

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" 

更多信息的文档:

  • https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-basics.html
  • https://cran.r-project.org/web/packages/RSelenium/vignettes/RSelenium-docker.html

这篇关于无法执行rsDriver(连接被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆