繁体   English   中英

RSelenium无法连接到主机rsDriver()

[英]RSelenium Couldn't connect to host rsDriver()

我试图用RSelenium抓取一个网站。 但是,当我想连接到Selenium服务器时遇到问题。

想象一下,我使用rsDriver()命令启动硒服务器和浏览器:

rsDriver(browser = c('firefox'))

这是生成的输出:

[1] "Connecting to remote server"
Fehler in checkError(res) :
Couldnt connect to host on http://localhost:4567/wd/hub.
Please ensure a Selenium server is running.
Zusätzlich: Warnmeldung:
In rsDriver(browser = c("firefox")) : Could not determine server status.

或者,我尝试了此命令(在stackoverflow的另一个线程中找到它):

remDr <- remoteDriver(remoteServerAddr = "localhost" 
                      , port = 4444L
                      , browserName = "htmlunit"
)
remDr$open()

但是失败了:

[1] "Connecting to remote server"
Fehler in checkError(res) : 
  Couldnt connect to host on http://localhost:4444/wd/hub.
  Please ensure a Selenium server is running.

这是我的sessioninfo:

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

locale:
[1] de_CH.UTF-8/de_CH.UTF-8/de_CH.UTF-8/C/de_CH.UTF-8/de_CH.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] seleniumPipes_0.3.7 whisker_0.3-2       magrittr_1.5        xml2_1.1.1          jsonlite_1.2        httr_1.2.1         
[7] RSelenium_1.7.1     wdman_0.2.2        

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9      XML_3.98-1.5     binman_0.1.0     assertthat_0.1   bitops_1.0-6     rappdirs_0.3.1   R6_2.2.0        
 [8] semver_0.2.0     curl_2.3         subprocess_0.8.0 tools_3.3.2      yaml_2.1.14      caTools_1.17.1   openssl_0.9.6   

我在macOS Sierra版本10.12.2上使用Firefox版本51.0.1(64位)。

任何帮助是极大的赞赏!

检查Selenium服务器是否正在运行。 您可以尝试自动运行一个:

library(RSelenium)
library(wdman)
selServ <- wdman::selenium(verbose = FALSE)

然后,您可以检查日志以查看是否存在任何问题:

selServ$log()

另外,您可以尝试手动运行Selenium Server:

library(RSelenium)
library(wdman)
selServ <- wdman::selenium(retcommand = TRUE, verbose = FALSE)

然后在终端中手动运行cat(selServ)的输出:

> cat(selServ)
/usr/bin/java -Dwebdriver.chrome.driver='/Users/admin/Library/Application Support/binman_chromedriver/mac64/2.27/chromedriver' -Dwebdriver.gecko.driver='/Users/admin/Library/Application Support/binman_geckodriver/macos/0.14.0/geckodriver' -Dphantomjs.binary.path='/Users/admin/Library/Application Support/binman_phantomjs/macosx/2.1.1/phantomjs-2.1.1-macosx/bin/phantomjs' -jar '/Users/admin/Library/Application Support/binman_seleniumserver/generic/3.0.1/selenium-server-standalone-3.0.1.jar' -port 4567

谢谢@jdharrison! 我遇到了类似的问题,感到困惑,因为昨天RSelenium仍然可以正常工作,但是今天它不再启动浏览器。 正在运行:

library(wdman)
selServ <- wdman::selenium(verbose = FALSE)
selServ$log()

向我显示该问题是由一夜之间下载的损坏的jarfile引起的:

"Error: Invalid or corrupt jarfile C:\\Users\\user.name\\AppData\\Local\\binman\\binman_seleniumserver\\generic\\3.8.0/selenium-server-standalone-3.8.0.jar"

RSelenium中的rsDriver()函数自动使用最新的selenium-server-standalone jar文件。 当我用以前的jarfile运行rsDriver时,一切都再次正常工作:

rD <- rsDriver(verbose = FALSE, version = "3.7.1")

暂无
暂无

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

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