Santhosh
Santhosh

Reputation: 11834

phantomjs global variables call in page.evaluate

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

Upvotes: 1

Views: 3767

Answers (1)

Cybermaxs
Cybermaxs

Reputation: 24556

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

});

Upvotes: 3

Related Questions