【问题标题】:Getting document from CouchDB with PhantomJS [duplicate]使用 PhantomJS 从 CouchDB 获取文档 [重复]
【发布时间】:2015-06-20 22:38:01
【问题描述】:

我正在编写一个函数来使用 PhantomJS 从 CouchDB 中读取文档:

function getDocument(dbName, id) {
  var dbPage = webpage.create();

  dbPage.open('http://127.0.0.1:5984/' + dbName + '/' + id, function (status) {
        console.log("GOT REPLY FROM SERVER:");
        console.log(dbPage.content);

        var foo = JSON.parse(dbPage.content);
        //Do something with foo...
      }
  });  
}

从 CouchDB (dbPage.content) 返回的内容如下所示: GOT REPLY FROM SERVER: <html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">{"_id":"1","_rev":"1-3d3190e791500c179bdd02716add5280","myData": "d"]} </pre></body></html>

剥离 html 以便我可以运行 JSON.parse 以获取表示文档的 javascript 对象的最佳方法是什么?

【问题讨论】:

    标签: javascript couchdb phantomjs


    【解决方案1】:

    对于非 html 内容,您可以使用 page.plainText 而不是 page.content

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多