diff --git a/grab12306.js b/grab12306.js index ef838c8..a5fc50b 100644 --- a/grab12306.js +++ b/grab12306.js @@ -29,7 +29,8 @@ grabStation(global).then(function() { //时刻表 return grabSchedule(global); }).then(function() { - var time = moment().subtract(beginTime); + const seconds = moment().unix() - beginTime.unix(); + var time = moment().startOf('day').seconds(seconds); logger.info("所有抓取已完成,共耗时"+time.format("H时mm分ss秒")); }).catch(logger.error); diff --git a/lib/grab_schedule.js b/lib/grab_schedule.js index 3b0f3a7..ed99606 100644 --- a/lib/grab_schedule.js +++ b/lib/grab_schedule.js @@ -51,7 +51,14 @@ var grabSchedule = function(global) { url: url, strictSSL: false }).then(function(res) { - var data = JSON.parse(res[1]); + var data; + try { + data = JSON.parse(res[1]); + } catch (error) { + logger.error("request error 将尝试再次抓取 12306的数据为:" + res[1]); + errorList.push(train); + return Promise.resolve(); + } if (!(data.httpstatus && data.httpstatus == 200)) { logger.error("request error 将尝试再次抓取 12306的数据为:" + res[1]); errorList.push(train);