我正在使用x-ray抓取网站,但我似乎无法在浏览器中显示正确的 JSON 输出。当我编写像 write('result.json')
这样的新 json 文档时,它工作得很好,但是现在当我尝试将其发送到浏览器时。我目前正在使用express作为网络框架。
下面创建了一个新的 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溪流。您已将其通过管道传输到 Node GET 响应以使其正常工作。
app.get('/api/standings', function(req, res, next){
x('http://www.dribbble.com', 'a', [{
url: '@href',
}]).write().pipe(res);
});
关于javascript - X-Ray 抓取并在服务器浏览器中呈现 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33583958/