2015-12-18 27 views
0

我使用Rselenium和phantomjs創建了一個刮板。有時候,我的程序查詢一個網站太久而且永遠不會結束。所以我正在寫一個超時處理程序。創建超時處理程序,使用Rselenium進行網絡報廢

library(RSelenium) 
library(R.utils) 
pJS <- phantom(pjs_cmd ="C:\\software\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe" ) 
UA<-'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0' 
eCap <- list(phantomjs.page.settings.userAgent=UA) 
remDr <- remoteDriver(browserName = "phantomjs", extraCapabilities = eCap) 
remDr$open(silent=T) 

time_out<-0 
tryCatch({withTimeout({ 
     remDr$navigate("http://stackoverflow.com/questions/14399205/in-r-how-to-make-the-variables-inside-a-function-available-to-the-lower-level-f") 
             }, envir=globalenv(),timeout=1.08); 
          }, TimeoutException=function(ex) { 
      time_out<<-1 
}) 

但我得到的錯誤:Undefined error in RCurl call.Error in queryRD(paste0(serverURL, "/session/", sessionInfo$id, "/url"), :

無論如何,如果我嘗試看看裏面remDr ...

remDr$getTitle()[[1]] 
[1] "In R, how to make the variables inside a function available to the lower level function inside this function?(with, attach, environment) - Stack Overflow" 

所以它的工作!但爲什麼我得到錯誤?

回答

0

請更新JAVA並檢查Selenium版本webdriver是否使用最新版本運行。解決了問題

相關問題