首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为R设置rselenium?

如何为R设置rselenium?
EN

Stack Overflow用户
提问于 2017-02-26 12:59:34
回答 2查看 14.7K关注 0票数 13

“那时候一切都好”。

自从firefox 49 (?)您不能再直接使用rselenium包了。我已经搜索了整个互联网寻找一个简单的如何手动设置rselenium,但没有找到任何相关的和最新的。

有人能提供给我和所有那些不知道如何操作的人吗?比如:

  1. 下载XY
  2. 开AB

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

代码语言:javascript
复制
require(RSelenium)

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

回答 2

Stack Overflow用户

发布于 2017-02-26 13:12:41

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

代码语言:javascript
复制
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

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

这在http://rpubs.com/johndharrison/RSelenium-Basics附录中有详细说明。然而,运行RSelenium的推荐方法是通过Docker容器。使用RSelenium的码头操作说明可在http://rpubs.com/johndharrison/RSelenium-Docker上找到

问题:

如果由于管理员权限或反病毒软件等其他变量可能出现问题,则可以手动运行Selenium服务器。最简单的方法是通过wdman包:

代码语言:javascript
复制
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

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

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

代码语言:javascript
复制
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

现在试着运行一个浏览器

代码语言:javascript
复制
remDr <- remoteDriver(port = 4567L, browserName = "chrome")
remDr$open()

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

票数 11
EN

Stack Overflow用户

发布于 2020-12-08 03:17:55

  1. https://www.docker.com/products/docker-desktop下载码头
  2. 在终端(或windows的cmd )中运行docker pull selenium/standalone-chrome-debug
  3. 在Desktop的仪表板中,转到左边的“图像”选项卡。在那之后,你应该看到这样的东西:

单击Run

  1. 弹出窗口就会出现。在那里,点击“可选设置”
  1. 在港口输入4445。单击“加号”,在将在端口上创建的其他输入上键入5901。它应该看起来像下面的图片。之后,单击Run。
  1. 现在,如果单击左侧的Containers / Apps选项卡,应该有如下内容:
  1. 在Rs控制台中,转到: install.packages("RSelenium")库(RSelenium) remDr <- remoteDriver( remoteServerAdd = "localhost",端口=4445 L,browser = "chrome“) remDr$open()

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

这些步骤还允许您使用VNC监视所发生的事情和调试。如果您需要了解更多关于它的知识,请访问https://www.realvnc.com/pt/connect/download/viewer/,更多的细节不在本主题的范围之内。

嗯,我认为这可以带您到一个点,您现在可以按照RSelenium的基本用法说明:https://cran.r-project.org/web/packages/RSelenium/vignettes/basics.html

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

我希望它能对你有帮助,就像你在一段时间前会帮助我一样。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42468831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档