利用nodejs的cheerio抓取网站数据

/*引入模块*/
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('获取数据出错')
})

  

上一篇:LeetCode之237. Delete Node in a Linked List


下一篇:Unity5 AssetBundle