HTTP small reptile var http=require (' http ') var cheerio=require (' Cheerio ') var url= ' http://www.imooc.com/learn/348 ' function Filter (HTML) {var $=cheerio.load (HTML); var chapters=$ ('. Mod-chapters ') var coursedata=[] Chapters.each (function (item) {var chapter=$ (this) VA R Chaptertitle=chapter.find (' strong '). Text () var videos=chapter.find ('. Video '). Children (' Li ') var chapterdat a={chaptertitle:chaptertitle, videos:[]} videos.each (function (item) {var video=$ (This). Find ('. Stydyvideo ') var videotitle=video.text () ChapterData.videos.push ({ Title:videotitle,})}) Coursedata.push (Chapterdata)}) return Coursedata}http.get (Url,fun Ction (res) {var html= ' Res.on (' data ', function (data) {html+=data}) Res.on (' End ', function () {var Data=filter (HTML); Console.log (data)}). On (' Error ', function () {})/** * Created by Administrator on2017-07-03. *///Event Module Episode no more than 10 listeners var eventemitter=require (' Events ') on an event. Eventemittervar life=new Eventemitter () life.on (' DDD ', function () {console.log (' 55555555 ')}) Life.on (' ddd ', function () {console.log (' 6666 ')}) function water () {}life.listeners (' ddd '). length//view the number of events eventemitter.listenercount (life, ' DDD ')//life.removelistener (' ddd ', water)//delete event listener life.emit (' DDD ')//Event Trigger//Delete all listener Events life.removealllisteners ()
Node--http Small Reptile & Event module