-1

I have a JS file to add headers as follows.

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();
    });
}

I am now executing the following phantoms command

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

Upon opening body.html I get an empty HTML file as follows.

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

Why the HTML source is not getting generated here.

3
  • 1
    try using service_args=['--ignore-ssl-errors=true'].see here stackoverflow.com/questions/23581291/… Commented Jan 8, 2015 at 6:40
  • I tried now phantomjs RequestURL.js service_args=['--ignore-ssl-errors=true'] http:////www.ubank.com.au > body.html still empty html Commented Jan 8, 2015 at 6:47
  • http:////www.ubank.com.au is definitely not a valid URL. Try http://www.ubank.com.au Commented Jan 8, 2015 at 11:13

1 Answer 1

2

1. Maybe page content is not loading with DOM start. (I had the same problem). You can set any timeout after load page.

2. Don't use page.content function. Better write simple execute in client-side. Like that:

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

Or, something like that. If you have any JS errors, please comment my post with this errors. Hope, its help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.