Javascript Phantomjs打印空的HTML源代码

Javascript Phantomjs打印空的HTML源代码,javascript,jquery,html,phantomjs,Javascript,Jquery,Html,Phantomjs,我有一个JS文件要添加如下标题 var webPage = require('webpage'); var system = require('system'); var page = webPage.create(); page.customHeaders = {"pragma": "akamai-x-feo-trace"}; page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebK

我有一个JS文件要添加如下标题

var webPage = require('webpage');
var system = require('system');
var page = webPage.create();

page.customHeaders = {"pragma": "akamai-x-feo-trace"};
page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"

if (system.args.length === 1) {
    console.log('Try to pass some args when invoking this script!');
} else {
    page.open(system.args[1], function (status) {
    var content = page.content;
    console.log(content);
    phantom.exit();
    });
}
我现在执行下面的phantoms命令

phantomjs RequestURL.jshttp:////www.ubank.com.au >body.html

打开
body.html
后,我得到一个空的html文件,如下所示

var webPage = require('webpage');
var system = require('system');
var page = webPage.create();

page.customHeaders = {"pragma": "akamai-x-feo-trace"};
page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36"

if (system.args.length === 1) {
    console.log('Try to pass some args when invoking this script!');
} else {
    page.open(system.args[1], function (status) {
    var content = page.content;
    console.log(content);
    phantom.exit();
    });
}


为什么没有在此处生成HTML源代码。

1。可能页面内容没有使用DOM start加载。(我也有同样的问题)。您可以在加载页面后设置任何超时

2.不要使用
page.content
功能。最好在客户端编写简单的execute。就像这样:

page.evaluate(function() {
    return document.body.outerHTML;
})

或者类似的。如果你有任何JS错误,请用这些错误评论我的帖子。希望,它的帮助

尝试使用服务_args=['--忽略ssl错误=true']。请参阅此处我现在尝试的
phantomjs RequestURL.js服务_args=['--忽略ssl错误=true']http:////www.ubank.com.au >body.html
仍然是空的html
http:////www.ubank.com.au
绝对不是有效的URL。试试
http://www.ubank.com.au