问题:如何在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):