【问题标题】:using phantomjs with RSelenium on windows 7在 Windows 7 上使用带有 RSelenium 的 phantomjs
【发布时间】:2017-09-20 19:16:36
【问题描述】:

我正在尝试将 PhantomJS 与 RSelenium 一起使用,但似乎遇到了问题:

require(RSelenium)
RSelenium::startServer()
remDr <- remoteDriver(browserName = "phantomjs", extraCapabilities = list(phantomjs.binary.path =    "C:/Users/home/Desktop/phantomjs-1.9.8-windows/phantomjs.exe"))
remDr$open()

这会导致:

$class
[1] "org.openqa.selenium.UnsupportedCommandException"

$additionalInformation
[1] "\nDriver info: driver.version: unknown"

我的sessionInfo() 如下:

$class
[1] "org.openqa.selenium.UnsupportedCommandException"

$additionalInformation
[1] "\nDriver info: driver.version: unknown"

更新: 不幸的是,下面的解决方案似乎不起作用:

[1] "Connecting to remote server"
Error:   Summary: UnknownError
         Detail: An unknown server-side error occurred while processing the command.
         class: java.lang.ClassNotFoundException

【问题讨论】:

  • 上面的信息已经是失败的迹象:驱动未知,捕获到异常。 open() 打开浏览器而不是特定的 url
  • 感谢您了解这一点。此问题已在 dev 分支上修复。我会在 CRAN 上更新版本。

标签: r selenium selenium-webdriver phantomjs


【解决方案1】:

此问题已修复 https://github.com/ropensci/RSelenium/commit/462ff26eb0e5578181b80cb5bc002ac1e8e68306。您可以尝试以下方法吗:

devtools::install_github("ropensci/RSelenium")
require(RSelenium)
psPath <- "C:/Users/home/Desktop/phantomjs-1.9.8-windows/phantomjs.exe"
RSelenium::startServer()
remDr <- remoteDriver(browserName = "phantomjs"
                      , extraCapabilities = list(phantomjs.binary.path = psPath))
remDr$open()

更新:

这似乎是新的 2.44 selenium 服务器和 ghostdriver 的问题,现在您可以在没有 Selenium 服务器的情况下直接驱动 phantom,直到问题在上游得到修复,或者您可以使用旧版本的 Selenium 服务器(2.43 正在使用 ghostdriver ):

# DRIVE phantomJS DIRECTLY
require(RSelenium)
# devtools::install_github("ropensci/RSelenium") # if the latest dev version is not currently installed
psPath <- "C:/Users/home/Desktop/phantomjs-1.9.8-windows/phantomjs.exe"
pJS <- phantom(pjs_cmd = psPath)
remDr <- remoteDriver(browserName = "phantomjs")
remDr$open()
# pJS$stop() # to close phantom server

【讨论】:

  • 好的,让我试一试。这是一个单独的问题,所以如果有帮助,我可以这样做:您是否有关于可以抛出的异常的文档或带有trycatch 的一些示例代码?
  • 刚刚尝试过:不幸的是,它没有像希望的那样工作
  • 您能否在github.com/ropensci/RSelenium/issues 上提出问题,我会调查一下。
  • 当然,现在就归档
  • 看起来这是新的 Selenium 服务器和 ghostdriver github.com/detro/ghostdriver/issues/397 的问题。我已经提交了对 github 的更新,它应该允许您使用自定义路径直接驱动 phantomjs。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
  • 1970-01-01
  • 2016-04-22
  • 1970-01-01
  • 2021-08-16
相关资源
最近更新 更多