Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send URL to Phantomjs?

screenshot.js

var page = require("webpage").create();
var homePage = "http://www.google.com/";
page.open(homePage);
page.onLoadFinished = function(status) {
  var url = page.url;
  console.log("Status:  " + status);
  console.log("Loaded:  " + url);
  page.render("google.png");
  phantom.exit();
};

Terminal:

bin/phantomjs screenshot.js

Question: Is there any way that I can send phantomjs the URL (value of var homePage above) somehow outside of screenshot.js so that its not hard coded inside the script?

like image 257
Chris Avatar asked Dec 06 '25 14:12

Chris


1 Answers

Add the url to the command line

bin/phantomjs screenshot.js http://www.google.com/

Here you have an example from the docs :https://github.com/ariya/phantomjs/blob/master/examples/arguments.js

var system = require('system');
if (system.args.length === 1) {
    console.log('Try to pass some args when invoking this script!');
} else {
    system.args.forEach(function (arg, i) {
            console.log(i + ': ' + arg);
    });
}
phantom.exit();
like image 174
maazza Avatar answered Dec 08 '25 04:12

maazza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!