2017-03-23 30 views
1

我收到以下错误:“ErrorError(checkError(res): Could not connect to host on http://localhost:4444/wd/hub。 请确保Selenium服务器正在运行。”RSelenium错误:无法连接到主机; 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

我还可以尝试什么?

回答

2

RSelenium::phantom函数已弃用。这有一个pjs_cmd我认为你参考上面的论点。或者使用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() 
+0

第二个选项为我工作(

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

虽然第一选择仍然给我:您可以使用rsDriver功能从RSeleniumphantomjs功能从wdman包相同的错误)。谢谢你的帮助! – jbohning

相关问题