我的Git bash里結果顯示怎么老是亂行,有時候還會少顯示個字?
為什么我的是這樣的? ?顯示到第三行就這樣了
var eventEmitter = require('events').EventEmitter
var life = new eventEmitter()?
life.setMaxListeners(11)
function water(who){
console.log('給' + who + '倒水')
}
life.on('求安慰',water)
life.on('求安慰',function(who){
console.log('給' + who + '揉肩')
})
life.on('求安慰',function(who){
console.log('給' + who + '做飯')
})
life.on('求安慰',function(who){
console.log('給' + who + '洗衣服')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。5')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。6')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。7')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。8')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。9')
})
life.on('求安慰',function(who){
console.log('給' + who + '。。。10')
}) ?
life.on('求安慰',function(who){
console.log('給' + who + '你想累死我?。?)
})
life.on('求溺愛',function(who){
console.log('給' + who + '買衣衣')
})
life.on('求溺愛',function(who){
console.log('給' + who + '交工資')
})
life.on('求溺愛',function(who){
console.log('給' + who + '交 話 費')
})
life.removeListener('求安慰',water) ?
var hasConfortListener = life.emit('求安慰','漢子')
var hasLovedListener = life.emit('求溺愛','妹子')
console.log(life.listeners('求安慰').length) ?
console.log(life.listeners('求溺愛').length)?
console.log(eventEmitter.listenerCount(life,'求安慰'))?
2017-08-20
我的是這樣的
2017-08-20
var http=require('http')
var cheerio = require('cheerio')
var url='http://www.xianlaiwan.cn/learn/348'
function filterChapters(html){
? ? var $ = cheerio.load(html)
? ? var chapters = $('.chapter')
? ? var courseData = []
? ? chapters.each(function(item){
? ? ? ? var chapter = $(this)
? ? ? ? var chapterTitle = chapter.find().text()
? ? ? ? var videos = chapter.find('.video').children('li')
? ? ? ? var chapterData={
? ? ? ? ? ? chapterTitle:chapterTitle,
? ? ? ? ? ? videos : []
? ? ? ? }
? ? ? ? videos.each(function(item){
? ? ? ? ? ? var video = $(this).find('.J-media-item')
? ? ? ? ? ? var videoTitle = video.text()
? ? ? ? ? ? var id = video.attr('href').split('video/')[1]
? ? ? ? ? ? chapterData.videos.push({
? ? ? ? ? ? ? ? title: videoTitle,
? ? ? ? ? ? ? ? id: id
? ? ? ? ? ? })
? ? ? ? })
? ? ? ? courseData.push(chapterData)
? ? })
? ? return courseData
}
function printCourseInfo(courseData){
? ? courseData.forEach(function(item){
? ? ? ? var chapterTitle = item.chapterTitle
? ? ? ? console.log(chapterTitle + '\n')
? ? ? ? item.videos.forEach(function(video){
? ? ? ? ? ? console.log('【' + video.id + '】' + video.title + '\n')
? ? ? ? })
? ? })
}
http.get(url,function(res){
? ? var html=''
? ? res.on('data',function(data){
? ? ? ? html+=data
? ? })
? ? res.on('end',function(){
? ? ? ? var courseData = filterChapters(html)
? ? ? ? printCourseInfo(courseData)
? ? })
}).on('error',function(){
? ? console.log('獲取課程數據出錯!')
})
2017-08-20
用你的代碼運行的,Git Bash和cmd里都是正常的呀