/*引入模块*/ var http = require('http') var url = 'http://www.cnblogs.com/txxt' var cheerio = require('cheerio') /*过滤函数*/ function filter(html) { var $ = cheerio.load(html) var titleData = []; var title = $('.postTitle').text(); console.log(title) } /*数据获取*/ http.get(url, function(res){ var html = ''; res.on('data',function(data) { html += data; }) res.on('end',function(){ filter(html) }) }).on('error',function(){ console.log('获取数据出错') })