CasperJs捕获超时和重启过程

时间:2015-06-09 19:03:58

标签: coffeescript event-handling phantomjs casperjs

问题:如何在tiemout错误上重启casperjs进程

问题 我运行一个爬行器,有时会超时:

[error] [phantom] Wait timeout of 5000ms expired, exiting.
Wait timeout of 5000ms expired, exiting.
Error: TypeError: 'null' is not an object (evaluating 'document.querySelector('#identify tbody tr:nth-of-type(' + (current * 2 + 2) + ') div.details>div').innerHTML')

无效解决方案 我将所有casper脚本放入一个我想在超时事件中重新启动的函数:

runCasper = () ->

  console.log ">>>>>>>>>>>>>>>>>>STARTING CASPER<<<<<<<<<<<<<<<<<<<<<<"

  #Starts Casper and Takes a Snapshot
  casper.start(url, () ->
    self = this
    this.viewport(1024, 768, ()->
      self.capture('screenshotsKv/start.png')
    )
  )


  #Iterate through all 
  .eachThen(plz, (response) ->
    lots of code


  .on( 'wait.timeout', (msg) ->
    this.echo( 'Error: ' + msg, 'ERROR' )
    log.aborted = log.aborted.concat(log.last + ' ' + new Date().toString())
    functionsFiles.saveLog(log)
    self.capture('screenshotsKv/' + log.last + ' ' + new Date().toString() + '.png')
    runCasper()
  )


  #Save all results into the database
  .run(() ->
    this.exit()
  )

#Starts Casper
runCasper()

我也试过了step.timeout,但都没有触发重启。

可能的原因(imho):

  • 因为整个过程终止,包括.on listener?
  • 听众错了?
  • 超时来自幻像,而聆听者仅限于casperjs?

0 个答案:

没有答案