【问题标题】:Chrome hangs/self closes when using RSelenium (Using R)使用 RSelenium 时 Chrome 挂起/自行关闭(使用 R)
【发布时间】:2018-03-23 05:10:57
【问题描述】:

尝试将 python 项目(使用 selenium 抓取 Twitter 推文而不使用 limited twitter api)转换为 R 编程。在 Python 中工作正常,但我想在 R 中重新创建它。R 新手,但如果有帮助,我有一些 MatLab 经验

install.packages("RSelenium") # install RSelenium 1.7.1

据我所知,该软件包已更新。因此,我需要使用其他功能,而不是 startserver()。但根据所有研究,我得到的答案有点矛盾,但都不起作用:

require(RSelenium) #used require() and library()
remDr <- remoteDriver(browserName = "chrome")
remDr$open()

我得到错误:

[1] "Connecting to remote server"
Error in checkError(res) : 
  Undefined error in httr call. httr output: Failed to connect to localhost port 4444: Connection refused

也试过了:

require(RSelenium)
remDr <- rsDriver(browser = c("chrome"))

我得到:

checking Selenium Server versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking chromedriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking geckodriver versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
checking phantomjs versions:
BEGIN: PREDOWNLOAD
BEGIN: DOWNLOAD
BEGIN: POSTDOWNLOAD
[1] "Connecting to remote server"

chrome 浏览器 (61.0.3163.100) 启动,但由于最后一行,我无法运行我的代码的下一行。浏览器在自动关闭之前保持打开大约半分钟,我收到此错误:

Selenium message:unknown error: unable to discover open pages
  (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 60.44 seconds
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:40.131Z'
System info: host: 'RENTEC-THINK', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: driver.version: unknown

Error:   Summary: UnknownError
     Detail: An unknown server-side error occurred while processing the command.
     Further Details: run errorDetails method

我尝试了多种不同的方法,包括下载 chrome 驱动程序(v2.33 应该支持 chrome v60-62 https://sites.google.com/a/chromium.org/chromedriver/downloads) 并在 removedriver 中包含路径或将路径添加为系统变量

就像我所做的任何事情都不起作用,好像 RSelenium 的更新搞砸了一切。我在做傻事吗?

我已经到了这样的地步,从我在网上看到的所有不一致的答案中,我发现自己在尝试不同代码行的不同组合,混合匹配所有内容等,拼命尝试让这个工作仅通过反复试验

我的下一个尝试是尝试找出 R 安装 RSelenium 的位置,然后查看代码中的内容:(

我也在考虑 docker,但我并没有真正为了让我的代码工作而安装单独的应用程序。

【问题讨论】:

    标签: r rselenium


    【解决方案1】:

    试试:

    remDr <- remoteDriver(browserName = "chrome")
    Sys.sleep(5)
    remDr$open()
    

    有时驱动程序尝试打开太快,您会收到“无法连接到 localhost 端口 4444:连接被拒绝”错误。

    【讨论】:

      【解决方案2】:

      以下内容对我有用。注意浏览器、selenium 和驱动版本...

      wdman::selenium(port = 4444L, geckover = "0.24.0", 
                      version = "3.141.59",check=FALSE, retcommand = TRUE) %>%
        system(wait=FALSE, invisible=FALSE)
      
      rmDrv = remoteDriver(extraCapabilities = list(marionette = TRUE),
                           browserName="firefox", port = 4444L)
      rmDrv$open()
      
      rmDrv$navigate("https://www.google.com")
      
      rmDrv$close()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-28
        • 2021-07-24
        • 1970-01-01
        相关资源
        最近更新 更多