Node--http Small Reptile & Event module

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.