问题描述
我想弄清楚为什么我的脚本没有将控制台日志输出到...控制台。
const Nightmare = require('nightmare')
const cheerio = require('cheerio');
const fs = require('fs');
// Consts
const url = 'https://www.mscl.org/live/scorecard/ed7941919f69b0e11e800fef/mHcehsPR9S86T3zQv';
const interval = 10*1000; // every 10 second
let mvcclivescore = {
battingTeam: '',score: 0,lastChecked: 0
};
let getData = html => {
const $ = cheerio.load(html);
$('div').each((i,elem) => {
if( i === 0 ){
mvcclivescore.battingTeam = $(elem).find('div.row:nth-child(1) div:nth-child(1) h5').html();
mvcclivescore.score = $(elem).find('div.row:nth-child(1) div:nth-child(2) h5').html();
mvcclivescore.lastChecked = new Date().toLocaleString();
console.log(mvcclivescore);
}
});
let data = JSON.stringify(mvcclivescore);
fs.writeFileSync('mvcclivescore.json',data);
}
function runMvccScrapper(){
console.log('Starting the scrapping');
const nightmare = Nightmare({ show: true })
nightmare
.goto(url)
.wait('body')
.wait('div#summaryTab.tab-pane.fade.in.table-responsive.borderless.active')
.evaluate(() => document.querySelector('div.container-fluid.liveMatchSummaryTab div.row div.col-md-6 div.container-fluid').innerHTML)
.end()
.then(response => {
getData(response);
}).catch(err => {
console.log(err);
}).then(()=>{
console.log('Scrapping is done');
console.log('/****************************/');
});
}
setInterval(function(){
console.log('/****************************/');
console.log('Time to run the job');
runMvccScrapper();
},interval);
这个脚本看起来很简单。打印到控制台的唯一内容是“运行作业的时间”,然后是 console.log('Starting the scrapping'); 就像噩梦根本不起作用或运行一样。
我在这里错过了什么?为什么这不起作用?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)