【问题标题】:Phantomjs prints empty HTML sourcePhantomjs 打印空的 HTML 源
【发布时间】:2015-01-08 06:32:41
【问题描述】:

我有一个 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();
    });
}

我现在正在执行以下幻象命令

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

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

<html><head></head><body></body></html>

为什么这里没有生成 HTML 源代码。

【问题讨论】:

  • 尝试使用 service_args=['--ignore-ssl-errors=true']。见这里stackoverflow.com/questions/23581291/…
  • 我现在尝试了phantomjs RequestURL.js service_args=['--ignore-ssl-errors=true'] http:////www.ubank.com.au > body.html 仍然是空的html
  • http:////www.ubank.com.au 绝对不是有效的 URL。试试http://www.ubank.com.au

标签: javascript jquery html phantomjs


【解决方案1】:

1. 可能页面内容未在 DOM 启动时加载。 (我有同样的问题)。您可以在加载页面后设置任何超时。

2.不要使用page.content函数。最好在客户端编写简单的执行。像这样:

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

或者,类似的东西。如果您有任何 JS 错误,请在我的帖子中评论此错误。希望,它的帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2019-12-30
    • 2013-12-25
    相关资源
    最近更新 更多