javascript - X-Ray 抓取并在服务器浏览器中呈现 json

标签 javascript json node.js x-ray

我正在使用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/

相关文章:

javascript - 带有 `width: 100%` 的样式 header 而不使用 `position` 属性

javascript - 管理没有时区的 moment.js 范围

json - 为什么 mapbox 拒绝我的 geojson 为无效。

sql - 如何在 Golang 中将 *sql.Rows 转换为类型化的 JSON

JAVA试图寻找年度最佳职位。不工作

javascript - NodeJS : Execute a function when UTC server time equals to time entry in firebase database

javascript - 使用 axios 在 ReactJS web worker 中调用 web api 方法

node.js - 我应该在 Electron 应用程序中的什么地方存储 OAuth 客户端密码?

javascript - 如何获得两个div之间的距离

javascript - 如何声明数组中的键值对并为其赋值