r - 如何为 R 设置 rselenium?

标签 r rselenium

“那时一切都更好”...

从 Firefox 49(?)开始,你不能再使用 rselenium 包了。我搜索了整个互联网以找到用于设置 rselenium 的简单操作手册,但没有找到任何相关且最新的内容。

有人可以为我和所有其他不知道的人提供一份简单的操作手册吗?喜欢:

  1. 下载 XY
  2. 打开AB

这样我就可以运行如下代码

require(RSelenium)

remDr <- remoteDriver(remoteServerAddr = "localhost", port = 4444L, 
browserName = "firefox")
remDr$open()

最佳答案

下载最新版本的RSelenium >= 1.7.1。运行以下命令:

library(RSelenium)
rD <- rsDriver() # runs a chrome browser, wait for necessary files to download
remDr <- rD$client
# no need for remDr$open() browser should already be open

如果您想要 Firefox 浏览器,请使用 rsDriver(browser = "firefox")

http://rpubs.com/johndharrison/RSelenium-Basics 附录中有详细说明。然而,运行 RSelenium 的推荐方法是通过 Docker 容器。有关将 Docker 与 RSelenium 结合使用的说明,请访问 http://rpubs.com/johndharrison/RSelenium-Docker

问题:

如果您遇到因管理员权限或其他变量(例如防病毒软件)而可能出现的问题,您可以手动运行 Selenium 服务器。最简单的方法是通过 wdman 包:

selCommand<- 
  wdman::selenium(jvmargs = c("-Dwebdriver.chrome.verboseLogging=true"), 
                  retcommand = TRUE)
> cat(selCommand)
C:\PROGRA~3\Oracle\Java\javapath\java.exe -Dwebdriver.chrome.verboseLogging=true -Dwebdriver.chrome.driver="C:\Users\john\AppData\Local\binman\binman_chromedriver\win32\2.27/chromedriver.exe" -Dwebdriver.gecko.driver="C:\Users\john\AppData\Local\binman\binman_geckodriver\win64\0.14.0/geckodriver.exe" -Dphantomjs.binary.path="C:\Users\john\AppData\Local\binman\binman_phantomjs\windows\2.1.1/phantomjs-2.1.1-windows/bin/phantomjs.exe" -jar "C:\Users\john\AppData\Local\binman\binman_seleniumserver\generic\3.0.1/selenium-server-standalone-3.0.1.jar" -port 4567

使用启用了 retcommand 选项的 wdman 函数之一将返回 将运行的命令行调用。

现在您可以在终端中运行 cat(selCommand) 的输出

C:\Users\john>C:\PROGRA~3\Oracle\Java\javapath\java.exe -Dwebdriver.chrome.verboseLogging=true -Dwebdriver.chrome.driver="C:\Users\john\AppData\Local\binman\binman_chromedriver\win32\2.27/chromedriver.exe" -Dwebdriver.gecko.driver="C:\Users\john\AppData\Local\binman\binman_geckodriver\win64\0.14.0/geckodriver.exe" -Dphantomjs.binary.path="C:\Users\john\AppData\Local\binman\binman_phantomjs\windows\2.1.1/phantomjs-2.1.1-windows/bin/phantomjs.exe" -jar "C:\Users\john\AppData\Local\binman\binman_seleniumserver\generic\3.0.1/selenium-server-standalone-3.0.1.jar" -port 4567
12:15:29.206 INFO - Selenium build info: version: '3.0.1', revision: '1969d75'
12:15:29.206 INFO - Launching a standalone Selenium Server
2017-02-08 12:15:29.223:INFO::main: Logging initialized @146ms
12:15:29.265 INFO - Driver class not found: com.opera.core.systems.OperaDriver
12:15:29.265 INFO - Driver provider com.opera.core.systems.OperaDriver registration is skipped:
Unable to create new instances on this machine.
12:15:29.265 INFO - Driver class not found: com.opera.core.systems.OperaDriver
12:15:29.266 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
12:15:29.271 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
 registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN10
2017-02-08 12:15:29.302:INFO:osjs.Server:main: jetty-9.2.15.v20160210
2017-02-08 12:15:29.317:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@c4c815{/,null,AVAILABLE}
2017-02-08 12:15:29.332:INFO:osjs.ServerConnector:main: Started ServerConnector@4af044{HTTP/1.1}{0.0.0.0:4567}
2017-02-08 12:15:29.333:INFO:osjs.Server:main: Started @257ms
12:15:29.334 INFO - Selenium Server is up and running

现在尝试运行浏览器

remDr <- remoteDriver(port = 4567L, browserName = "chrome")
remDr$open()

如果您无法手动运行 Selenium 服务器,那么您需要将问题(包括相关日志文件)解决到 Selenium 项目或相应的驱动程序项目(chromedriver/geckodriver/ghostdirver 等)

关于r - 如何为 R 设置 rselenium?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42468831/

相关文章:

css - NoSuchElementException 使用 RSelenium 抓取 ESPN

r - 使用每个可能值的固定概率模拟数据集

r - 无法在 R 中安装 base64enc 包

r - 对于相同的变量,有什么办法可以区别对待 NA 吗?

r - 当 N 很小时,隐藏 geom_boxplot() 中的框和须线

r - 文档在 RSelenium 中完成

r - 在 Firefox 中使用 RSelenium 的 open.connection(con, "rb") : HTTP error 403. 错误

css - 具有长名称的 Shiny selectInput/pickerInput 应该溢出侧边栏

r - 如何使用 RSelenium 在网页中同时按下两个键(即 control-s)?

Selenium 问题