nodejs实战:小爬虫

var http=require('http');
var url='http://www.website.com/path';
http.get(url,function(res){
    var html='';
    res.on('data',function(data){
        html+=data;
    })
    res.on('end',function(){
        //对HTML进行处理,取出自己有用的内容
    })
}).on('error',function(e){
    console.log('读取网页错误,Error: '+e.message);
})

对读取出来的元素进行处理可以用cheerio模块或则正则表达式

原文地址:https://www.cnblogs.com/zhenxianluo/p/6062698.html