我正在使用x-ray来抓取网站,但我似乎无法在浏览器中显示正确的JSON输出。它工作正常,当我写一个新的json文档,如write('result.json')
,但现在当我尝试将其发送到浏览器。我目前正在使用express作为Web框架。
下面创建一个新的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
}
答案 0 :(得分:1)
.write会返回enstore个流。您已将它传递给您的节点GET响应以使其正常工作。
app.get('/api/standings', function(req, res, next){
x('http://www.dribbble.com', 'a', [{
url: '@href',
}]).write().pipe(res);
});