如何使用phantomJS从javascript生成HTML? [英] How to get html generated from javascript using phantomJS?

查看:231
本文介绍了如何使用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.

这篇关于如何使用phantomJS从javascript生成HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆