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