【问题标题】:How to set up rselenium for R?如何为 R 设置 rselenium?
【发布时间】:2017-07-17 01:37:26
【问题描述】:

“那时一切都好”...

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

谁能提供给我和其他不知道简单操作指南的人?喜欢:

  1. 下载 XY
  2. 打开 AB

所以我可以运行如下代码

require(RSelenium)

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

【问题讨论】:

  • 根据您要执行的操作,您可能想尝试github.com/hrbrmstr/splashr,但似乎有数百人(如果不是数千人)能够按照您的要求进行操作而没有问题。
  • 我用过 splashr 也可以推荐一下????

标签: r rselenium


【解决方案1】:

下载最新版本的RSelenium &gt;= 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 容器。可以在http://rpubs.com/johndharrison/RSelenium-Docker找到使用 Docker 和 RSelenium 的说明

问题:

如果您有可能由于管理员权限或其他变量(例如防病毒软件)而出现的问题,您可以手动运行 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 等)

【讨论】:

  • 当我运行rD &lt;- rsDriver() cmd 时,RSrudio 在BEGIN: POSTDOWNLOAD 崩溃。我收到的最后一条消息是:“BEGIN: POSTDOWNLOAD 此应用程序已请求运行时以不寻常的方式终止它。”
  • 你能看看这个问题吗? stackoverflow.com/questions/66996370/… 谢谢!
【解决方案2】:
  1. https://www.docker.com/products/docker-desktop下载Docker

  2. 在终端中运行docker pull selenium/standalone-chrome-debug(或windows的cmd)

  3. 在 Docker Desktop 的仪表板中,转到左侧的“图像”选项卡。之后,您应该会看到如下内容: 点击运行

  4. 将出现一个弹出窗口。在那里,单击“可选设置”

  5. 在端口上键入 4445。单击“加号”,在将在端口上创建的另一个输入上键入5901。它应该如下图所示。之后,单击运行。

  6. 现在,如果您单击左侧的 Containers / Apps 选项卡,应该会出现如下内容:

  7. 在 Rs 控制台中,转到:

    install.packages("RSelenium")
    library(RSelenium)
    
    remDr <- remoteDriver(
            remoteServerAdd = "localhost",
            port = 4445L,
            browser = "chrome"
    )
    
    remDr$open()
    

每次您希望 RSelenium 工作时,您都需要像在上面的第 3 步和第 5 步中那样运行 Docker 容器。

这些步骤还允许您使用 VNC 观察发生的情况并进行调试。如果您需要了解它,请转到https://www.realvnc.com/pt/connect/download/viewer/ 更多详细信息超出了本主题的范围。

好吧,我认为这可以带你到一个点,你现在可以按照这些 RSelenium 基本用法小插图的说明进行操作:https://cran.r-project.org/web/packages/RSelenium/vignettes/basics.html

您还应该阅读与暴露端口相关的安全性以及如何处理它。 这些来自 R Consortium 的视频可能会从这里帮助您: https://www.youtube.com/watch?v=OxbvFiYxEzIhttps://www.youtube.com/watch?v=JcIeWiljQG4

我希望它可以帮助你,就像你前段时间帮助我一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-28
    • 2016-06-06
    • 1970-01-01
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多