使用PhantomJS从CouchDB获取文档

Getting document from CouchDB with PhantomJS

本文关键字:获取 文档 CouchDB PhantomJS 使用      更新时间:2023-09-26

我正在编写一个函数,用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对象?

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