本文介绍了无法执行 rsDriver(连接被拒绝)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法使用 R selenium.这是第一步和我的输出:
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.
大家 似乎 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
)或在 Rshell('docker pull selenium/standalone-firefox')
- 通过在命令行中运行来启动服务器:
docker run -d -p 4445:4444 selenium/standalone-firefox
或在 Rshell('docker run -d -p 4445:4444selenium/standalone-firefox')
- 然后运行
remDr .该文档建议使用虚拟机进行一些不同的操作,但我无法使其正常工作.
- install docker
- run it, restart computer as requested
- pull image by running in command line:
docker pull selenium/standalone-firefox
(orchrome
instead offirefox
) or in Rshell('docker pull selenium/standalone-firefox')
- start server by running in command line:
docker run -d -p 4445:4444 selenium/standalone-firefox
or in Rshell('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(连接被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!