如何使用 RSelenium 打开谷歌浏览器? [英] How to open Google Chrome with RSelenium?

查看:57
本文介绍了如何使用 RSelenium 打开谷歌浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 RSelenium,我想打开和浏览 Google Chrome.但是,当我想从 R 打开浏览器时,总是会出错.使用以下代码:

I am using RSelenium and I want to open and navigate Google Chrome. However, I always get an error when I want to open the browser from R. The following code is used:

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.我该怎么办?

The same code works for Firefox. What can I do about it?

推荐答案

即使安装了 Google Chrome,Selenium 仍然需要一些东西.这是chromedriver".chromedriver"可以在在这个网站上下载. 目前,最新版本是 2.25.例如,如果使用的是 Windows,则需要下载文件chromedriver_win32.zip".

Even though Google Chrome is installed, there is still something missing that is needed by Selenium. This is the "chromedriver". "chromedriver" can be downloaded on this website. Currently, the most recent version is 2.25. For instance, if one is using Windows, the file "chromedriver_win32.zip" needs to be downloaded.

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

When the file is downloaded, extract the file in it, i.e. "chromedriver.exe". Place "chromedriver.exe" where you want it to be. I put it in "User/Documents/R".

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

In the last step, you need to add the folder where "chromedriver.exe" is located to the system path. A description for adding a folder to the system path can be found here.

现在,可以重新启动R并运行代码.

Now, one can restart R and run the code.

这篇关于如何使用 RSelenium 打开谷歌浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆