繁体   English   中英

RSelenium错误:无法连接到主机; Selenium服务器未运行

[英]RSelenium Error: Can't Connect to Host; Selenium Server is not running

我收到以下错误:“ checkError(res)中的错误:无法连接到http:// localhost:4444 / wd / hub上的主机 。请确保Selenium服务器正在运行。”

我正在使用Mac版本10.9.5,并下载了所有最新版本的软件包和Java。 我的代码是:

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

我还能尝试什么?

不推荐使用RSelenium::phantom函数。 这有一个pjs_cmd参数,我认为您在上面已经提到过。 您可以使用rsDriver功能从RSeleniumphantomjs从功能wdman包:

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()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM