抓取访问网页空值啊
const router = require(‘koa-router’)({
prefix: ‘/weapp’
})
var _fn,_fn1
https = require(‘https’)
router.get(’/user/*’, function (req, next){
var path = “in_theaters”;
_fn.getData(path, function (data) {
req.response.body = data //浏览器显示不了
});
})
_fn = {
getData: function (path, callback) {
https.get( //是不是这里的问题呢
{
hostname: ‘www.baidu.com’,
path: ‘’
}, function (res) {
var body = [];
res.on(‘data’, function (chunk) {
body.push(chunk);
});
res.on(‘end’, function () {
body = Buffer.concat(body);
callback(body.toString())
})
}
)
}
}
module.exports = router