RSelenium错误:无法连接到主机; Selenium服务器未运行 [英] RSelenium Error: Can't Connect to Host; Selenium Server is not running
问题描述
我收到以下错误:"checkError(res)中的错误: 无法连接到 http://localhost:4444/wd/hub 上的主机. 请确保Selenium服务器正在运行."
I am getting the following error: "Error in checkError(res) : Couldnt connect to host on http://localhost:4444/wd/hub. Please ensure a Selenium server is running."
我正在使用Mac版本10.9.5,并下载了所有最新版本的软件包和Java.我的代码是:
I'm using a mac version 10.9.5, and downloaded all of the latest versions of packages and java. My code is:
library(rvest)
library(RSelenium)
library(wdman)
setwd(Path to selenium standalone file)
pJS <- phantomjs(pjs_cmd = "/phantomjs-2.1.1-macosx/bin/phantomjs")
remDr <- remoteDriver(browserName = "phantomjs")
Sys.sleep(5)
remDr$open(silent = FALSE)
然后我得到了提到的错误.我尝试在终端中使用"java -jar selenium-server-standalone.jar"命令(在我们使用cd命令导航到正确的目录之后).我尝试在remoteDriver()函数中更改端口(更改为4444、5556).我已经尝试了各种Sys.sleep()时间(最多20秒).当我搜索此错误时,大多数修复是针对FireFox或Windows的,不适用于使用PhantomJS
And then I get the mentioned error. I've tried using the "java -jar selenium-server-standalone.jar" command in the terminal (after us the cd command to navigate to the correct directory). I've tried changing my port in the remoteDriver() function (to 4444, 5556). I've tried various Sys.sleep() times (up to 20 seconds). When I googled this error, most of the fixes were for FireFox or Windows, and not applicable to using PhantomJS
我还能尝试什么?
推荐答案
不推荐使用RSelenium::phantom
函数.这有一个pjs_cmd
参数,我认为您在上面已经提到过.您可以使用RSelenium
中的rsDriver
函数或wdman
包中的phantomjs
函数:
The RSelenium::phantom
function is deprecated. This had a pjs_cmd
argument which I think you refer to above. You can use the rsDriver
function from the RSelenium
or the phantomjs
function from the wdman
package:
library(RSelenium)
rD <- rsDriver(browser = "phantomjs")
remDr <- rD[["client"]]
# no need for remDr$open a phantom browser is already initialised
remDr$navigate("http://www.google.com/ncr")
....
....
# clean up
rm(rD)
gc()
或者使用wdman
程序包
library(RSelenium)
library(wdman)
pDrv <- phantomjs(port = 4567L)
remDr <- remoteDriver(browserName = "phantomjs", port = 4567L)
remDr$open()
remDr$navigate("http://www.google.com/ncr")
...
...
# clean up
remDr$close()
pDrv$stop()
这篇关于RSelenium错误:无法连接到主机; Selenium服务器未运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!