X-Ray在服务器浏览器中抓取和呈现json
问题描述:
我使用x-ray来抓取网站,但是我似乎无法在浏览器中显示正确的JSON输出。它工作正常,当我写一个像write('result.json')
这样的新json文档时,现在当我尝试将其发送到浏览器时。我现在使用express作为web框架。X-Ray在服务器浏览器中抓取和呈现json
这下面创建一个新的result.json文件并显示正确的json输出(在dribbble.com上的url)。但是,因为我不想在浏览器中显示它?
app.get('/api/standings', function(req, res, next){
x('http://www.dribbble.com', 'a', [{
url: '@href',
}]).write()
'results.json'
});
我已经试过
app.get('/api/standings', function(req, res, next){
res.send(x('http://www.dribbble.com', 'a', [{
url: '@href',
}]).write());
});
怪异的输出错误
{
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": [
],
"length": 0,
"pipes": null,
"pipesCount": 0,
"flowing": null,
"ended": false,
"endEmitted": false,
"reading": false,
"sync": true,
"needReadable": false,
"emittedReadable": false,
"readableListening": false,
"defaultEncoding": "utf8",
"ranOut": false,
"awaitDrain": 0,
"readingMore": false,
"decoder": null,
"encoding": null
},
"readable": true,
"domain": null,
"_events": {
},
"_eventsCount": 0
}
答
的.WRITE将返回一个enstore流。你已经将它传递给你的节点GET响应来使它工作。
app.get('/api/standings', function(req, res, next){
x('http://www.dribbble.com', 'a', [{
url: '@href',
}]).write().pipe(res);
});