简体   繁体   English

如何使用RSelenium打开Goog​​le Chrome?

[英]How to open Google Chrome with RSelenium?

I am using RSelenium and I want to open and navigate Google Chrome. 我正在使用RSelenium,我想打开并浏览谷歌浏览器。 However, I always get an error when I want to open the browser from R. The following code is used: 但是,当我想从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

The same code works for Firefox. 相同的代码适用于Firefox。 What can I do about it? 我能做些什么呢?

Even though Google Chrome is installed, there is still something missing that is needed by Selenium. 即使安装了Google Chrome,Selenium仍然需要一些东西。 This is the "chromedriver". 这是“chromedriver”。 "chromedriver" can be downloaded on this website. “chromedriver”可以在这个网站上下载 Currently, the most recent version is 2.25 . 目前, 最新版本是2.25 For instance, if one is using Windows, the file "chromedriver_win32.zip" needs to be downloaded. 例如,如果使用Windows,则需要下载文件“chromedriver_win32.zip”。

When the file is downloaded, extract the file in it, ie "chromedriver.exe". 下载文件后,将文件解压缩,即“chromedriver.exe”。 Place "chromedriver.exe" where you want it to be. 将“chromedriver.exe”放在您想要的位置。 I put it in "User/Documents/R". 我把它放在“User / Documents / R”中。

In the last step, you need to add the folder where "chromedriver.exe" is located to the system path. 在最后一步中,您需要将“chromedriver.exe”所在的文件夹添加到系统路径中。 A description for adding a folder to the system path can be found here. 可以在此处找到有关将文件夹添加到系统路径的说明

Now, one can restart R and run the code. 现在,可以重新启动R并运行代码。

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

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