如何使用phantomJS从javascript生成HTML?
问题描述:
var page = require('webpage').create();
page.open(url, function (status) {
if (status === 'fail') {
console.log("fail");
} else {
console.log(page.evaluate(function () {
var t0 = document.body.innerHTML;
return t0;
}));
}
phantom.exit();
});
当我这样做时,我无法获得从js生成的html.
When I do this way, I can't get the html generated from js.
答
这不是将任何内容从页面范围返回到幻像范围的正确方法.
This is not the correct way to return anything from the page scope to the phantom's scope.
您应该考虑使用
window.callPhantom方法和page.onCallback事件.
window.callPhantom method and page.onCallback event.