RSelenium 通过 docker

Ker*_*eri 5 selenium r rselenium

我的操作系统是 Windows 8.1,我有 R 的 3.3.3 版。

我已经安装了 RSelenium 软件包,并尝试使用它来运行它:

library("RSelenium")
#start RSelenium server
startServer()
checkForServer()
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error: checkForServer is now defunct. Users in future can find the function in 
file.path(find.package("RSelenium"), "examples/serverUtils"). The
recommended way to run a selenium server is via Docker. Alternatively
see the RSelenium::rsDriver function.
Run Code Online (Sandbox Code Playgroud)

RSelenium 打开的方式有什么变化吗?我搜索错误,我只找到了这个,但这对我没有帮助。我能做什么?

我尝试的另一种方法是从这里下载 chromedrive ' https://sites.google.com/a/chromium.org/chromedriver/downloads '

并使用此脚本: require(RSelenium) cprof <- getChromeProfile("C:/Users/Peri/Desktop/chromedriver/chromedriver.exe", "Profile 1")

require(RSelenium)
remDr <- remoteDriver(remoteServerAddr = "localhost" 
                      , port = 4444
                      , browserName = "chrome", extraCapabilities = cprof
)
remDr$open()
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Error in checkError(res) : 
  Couldnt connect to host on http://localhost:4444/wd/hub.
  Please ensure a Selenium server is running.
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能运行 chrome 而不是预默认浏览器 Firefox?

Dan*_*elS 1

您需要使用该功能rsDriver。Selenium 版本希望您使用 Docker(我也推荐),但如果您对此不熟悉,您可以这样做。

rsdriver 将管理运行 Selenium 服务器所需的二进制文件。这提供了 wdman::selenium 函数的包装器。

以下是启动 Chrome 浏览器所需执行的操作:

driver<- rsDriver()
remDr <- driver[["client"]]
Run Code Online (Sandbox Code Playgroud)

然后你就可以使用它了:

remDr$navigate("http://www.google.de")
remDr$navigate("http://www.spiegel.de")
Run Code Online (Sandbox Code Playgroud)

并停止它:

remDr$close()
Run Code Online (Sandbox Code Playgroud)