爬接口数据
var https = require('https');
https.get('https://api.readhub.cn/topic?lastCursor=76823&pageSize=20',function(res,req){
var html='';
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
console.info(html);
})
console.log(html);
})
爬页面数据
var https = require('https');
const hupuUrl = 'https://bbs.hupu.com/selfie';
https.get(hupuUrl,function(res,req){
var html='';
res.on('data',function(data){
html+=data;
});
res.on('end',function(){
console.info(html);
})
console.log(html);
})
另一种方式:
SuperAgent
superagent它是一个强大并且可读性很好的轻量级ajaxAPI,是一个关于HTTP方面的一个库,而且它可以将链式写法玩的出神入化
api res.text包含为被解析的响应数据
var superagent = require('superagent');
superagent .get('/a