1

I want to know how to use a varaible globally in phantomjs so that it can be used in the page.evaluate function also.

I have gone through some previous answers but but able to understand well

Santhosh
  • 9,965
  • 20
  • 103
  • 243

1 Answers1

3

JSON-serializable arguments can be passed to page.evaluate. Here is a very basic the following example using this technique :

page.open('http://stackoverflow.com/', function(status) {

  var title = page.evaluate(function(s) {
    return document.querySelector(s).innerText;
  }, 'title');

  console.log(title);
  phantom.exit();

});
Cybermaxs
  • 24,378
  • 8
  • 83
  • 112