在Mac sierra上使用Rselenium

时间:2017-01-06 02:15:58

标签: r selenium web-scraping phantomjs rselenium

似乎每次我更新操作系统时,R或任何浏览器Rselenium都会停止工作。我无法再使用任何浏览器--Firefox,Chrome或PhantomJS。我在下面发布了我的代码。

会话信息:

sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.2

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rvest_0.3.2.9000 xml2_1.0.0       RSelenium_1.6.2 

loaded via a namespace (and not attached):
 [1] httr_1.2.1     magrittr_1.5   R6_2.2.0       tools_3.3.2    curl_2.3       Rcpp_0.12.8   
 [7] jsonlite_1.2   caTools_1.17.1 openssl_0.9.6  bitops_1.0-6   XML_3.98-1.4  

我的工作流程如下:

  1. PhantomJS:使用节点npm在终端安装(安装节点npm with brew:brew install node

    npm install -g phantomjs
    phantomjs --version #To check if it installed
        2.1.1  #It did
    

    进入我的R会话:

    library(RSelenium) 
    ptm <- phantom() #also tried running checkForServer() and startServer() first but both were deprecated with no substitute stated...
    
  2.   

    [错误 - 2017-01-06T01:55:35.240Z] GhostDriver - main.fail -   { “线”:85, “sourceURL”: “phantomjs://code/main.js”, “堆”:“全局   代码@ phantomjs://code/main.js:85:56" }

         

    phantomjs://platform/console++.js:263错误

        rd <- remoteDriver(browserName = 'phantomjs')
        rd$open()
    
      

    [1]“连接到远程服务器”错误:摘要:未知错误
      详细信息:处理时出现未知的服务器端错误   命令。 class:java.util.concurrent.TimeoutException更多   详细信息:运行errorDetails方法

    1. Chromedriver:从https://chromedriver.storage.googleapis.com/index.html?path=2.27/下载,二进制文件放在/usr/local/bin

      rd <-remoteDriver(browserName = 'chrome')
      rd$open() #At this point, Google Chrome opens up for 1 second and then closes and an error pops up
      
    2.   

      Selenium消息:会话未从未知错误创建异常:   Runtime.evaluate缺少'wasThrown'(会话信息:   chrome = 55.0.2883.95)(驾驶信息:chromedriver = 2.23.409710   (0c4084804897ac45b5ff65a690ec6583b97225c0),platform = Mac OS X 10.12.2   x86_64)(警告:服务器未提供任何堆栈跟踪   信息)命令持续时间或超时:1.09秒构建信息:   版本:'3.0.0-beta2',修订版:'2aa21c1',时间:'2016-08-02   15:03:28 -0700'系统信息:主持人:'Cyrus-M.local',ip:'10 .0.1.3',   os.name:'Mac OS X',os.arch:'x86_64',os.version:'10 .12.2',   java.version:'1.8.0_101'驱动程序信息:   org.openqa.selenium.chrome.ChromeDriver

           

      错误:摘要:SessionNotCreatedException详细信息:新会话   无法创建。类:   org.openqa.selenium.SessionNotCreatedException进一步的细节:运行   errorDetails方法

      1. Firefox:在/usr/local/bin中安装了gecko驱动程序(如果没有这个,以下代码会产生错误,表明我需要安装gecko驱动程序)

        remDr <- remoteDriver$new()
        remDr$open() #a blank Firefox page opens up but then the following error is produced)
        
      2.   

        [1]“连接到远程服务器”

             

        Selenium消息:不支持的Marionette协议版本2,需要3   (警告:服务器未提供任何堆栈跟踪信息)   命令持续时间或超时:1.06秒构建信息:版本:   '3.0.0-beta2',修订版:'2aa21c1',时间:'2016-08-02 15:03:28 -0700'   系统信息:主持人:'Cyrus-M.local',ip:'10 .0.1.3',os.name:'Mac OS   X',os.arch:'x86_64',os.version:'10 .12.2',java.version:   '1.8.0_101'驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver

             

        错误:摘要:UnknownError详细信息:未知的服务器端错误   处理命令时发生。类:   org.openqa.selenium.WebDriverException进一步的细节:运行   errorDetails方法

            remDr$navigate("http://www.google.com")
        
          

        checkError(res)出错:httr调用中的未定义错误。 HTTR   输出:length(url)== 1不为TRUE

        非常感谢任何帮助。

        更新

        将Firefox升级到测试版(51.0b11)后,我可以成功浏览,但问题仍然存在,使用Chrome和PhantomJS。

        remDr <- remoteDriver$new()
        remDr$open()
        
        [1] "Connecting to remote server"
        $rotatable
        [1] FALSE
        
        $raisesAccessibilityExceptions
        [1] FALSE
        
        $appBuildId
        [1] "20170103031119"
        
        $version
        [1] ""
        
        $platform
        [1] "MAC"
        
        $proxy
        named list()
        
        $command_id
        [1] 1
        
        $nativeEvents
        [1] TRUE
        
        $specificationLevel
        [1] 0
        
        $acceptSslCerts
        [1] FALSE
        
        $processId
        [1] 7529
        
        $webdriver.remote.sessionid
        [1] "64ac4d92-5761-4865-ba60-9cfaafe92a14"
        
        $browserVersion
        [1] "51.0"
        
        $platformVersion
        [1] "16.3.0"
        
        $XULappId
        [1] "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
        
        $browserName
        [1] "firefox"
        
        $takesScreenshot
        [1] TRUE
        
        $javascriptEnabled
        [1] TRUE
        
        $takesElementScreenshot
        [1] TRUE
        
        $platformName
        [1] "darwin"
        
        $cssSelectorsEnabled
        [1] TRUE
        
        $id
        [1] "64ac4d92-5761-4865-ba60-9cfaafe92a14"
        
        remDr$navigate("http://www.google.com") #Firefox opens up and browsing is accessible
        

0 个答案:

没有答案
相关问题