Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created June 24, 2013 12:03
Show Gist options
  • Save thecodejunkie/5849584 to your computer and use it in GitHub Desktop.
Save thecodejunkie/5849584 to your computer and use it in GitHub Desktop.
var page = require('webpage').create();
var system = require('system');
var address;
address = system.args[1];
console.log(address);
page.open(address, function(status) {
console.log(status);
});
console.log('Done');
phantom.exit();
@robashton
Copy link

If the file doesn't finish loading you'll not get anything I've found - the code you have is valid though.

I never use PhantomJS in this way, I spawn it up on the command line and interact with it via WebDriver, it's hella lot more stable that way.

@thecodejunkie
Copy link
Author

It looks like it works if I move the phantom.exit() to inside the callback that is passed to open. I was just putting it outside since the PhantomJS docs only said

"It is very important to call phantom.exit at some point in the script, otherwise PhantomJS will not be terminated at all."

@robashton
Copy link

Lol - yes sorry ,obvious thing - if you call it at the end it'll be called before the page is opened and you'll never get the callback

@robashton
Copy link

My tests tend to do

before(function(done) {
  setupPhantom(done)
})

after(function(done) {
  closePhantom()
})

@thecodejunkie
Copy link
Author

Oooh, hehe yeah that make sense. Cheers!

@thecodejunkie
Copy link
Author

I've not gotten that far.. literally using it for the first time today and I'm following their "Getting Started" section before I dig any deeper :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment