如何用 RSelenium 打开 Google Chrome?

How to open Google Chrome with RSelenium?

我正在使用 RSelenium,我想打开并导航 Google Chrome。但是,我想从R打开浏览器时总是报错,使用了如下代码:

library("RSelenium")
startServer()
mybrowser <- remoteDriver(browserName = "chrome")
mybrowser$open()

[1] "Connecting to remote server"
Error:   Summary: UnknownError
 Detail: An unknown server-side error occurred while processing the command.
 class: java.lang.IllegalStateException

相同的代码适用于 Firefox。我该怎么办?

即使安装了 Google Chrome,仍然缺少一些 Selenium 需要的东西。这就是"chromedriver"。 "chromedriver"可以下载on this website. Currently, the most recent version is 2.25。例如,如果使用 Windows,则需要下载文件 "chromedriver_win32.zip"。

下载文件后,解压其中的文件,即"chromedriver.exe"。将 "chromedriver.exe" 放在您想要的位置。我把它放在 "User/Documents/R"。

最后一步,需要将"chromedriver.exe"所在的文件夹添加到系统路径中。可以找到添加文件夹到系统路径的说明here.

现在,可以重新启动 R 和 运行 代码。