我正在尝试用RSelenium抓一个网站。但是,当我想连接到Selenium服务器时,我遇到了问题。
想象一下,我使用rsDriver()命令启动selenium服务器和浏览器:
brew install libimobiledevice
这是生成的输出:
rsDriver(browser = c('firefox'))
或者我尝试了这个命令(在stackoverflow上的另一个线程中找到它):
[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.
但它失败了:
remDr <- remoteDriver(remoteServerAddr = "localhost"
, port = 4444L
, browserName = "htmlunit"
)
remDr$open()
这是我的sessioninfo:
[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.
我在macOS Sierra版本10.12.2上使用Firefox版本51.0.1(64位)。
非常感谢任何帮助!
答案 0 :(得分:4)
检查Selenium Server是否正在运行。您可以尝试自动运行一个:
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
答案 1 :(得分:3)
谢谢@jdharrison!我遇到了类似的问题并且感到困惑,因为昨天RSelenium仍然工作正常,但今天它不再启动浏览器了。运行:
Rails.application.routes.draw do
mount Dashing::Engine, at: Dashing.config.engine_path
resources :bills
resources :unit_types, :except => [:show]
end
告诉我这个问题是由一夜之间下载的损坏的jar文件引起的:
library(wdman)
selServ <- wdman::selenium(verbose = FALSE)
selServ$log()
RSelenium中的rsDriver()函数自动使用最新的selenium-server-standalone jarfile。当我用之前的jarfile运行rsDriver时,一切正常工作:
"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"