Santhosh
Santhosh

Reputation: 11788

phantomjs command line variable

I am using linux and phantomjs to test some javascript

      var page = require('webpage').create();
      var fs = require('fs');
      var address = system.args[1];
      page.onConsoleMessage = function (msg) {
          console.log('Page title is ' + msg);
      };
      page.open(address, function (status) {
          //page.open("http://vedabase.net/sb/1/1/13/en", function (status) {
          //page.open("file:///home/simha/.public_html/13.htm", function (status) { 
          //page.open("http://localhost/~simha/13.htm", function (status) {   
          page.evaluate(function () {


              element2 = document.evaluate('html/body/table/following::p[1]',
                  document,
                  null,
                  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                  null);
              thisImg1 = element2.snapshotItem(0)
              console.log(thisImg1);
              thisImg1.childNodes[1].textContent = ""



              element = document.evaluate('html/body/table | //p[text()="SYNONYMS"] | //p[text()="SYNONYMS"]/following-sibling::p[following::p[text()="TRANSLATION"]] | //p[text()="PURPORT"] | //p[text()="PURPORT"]/following-sibling::p|//a[text()="Bhaktivedanta VedaBase"]|//a[text()="Śrīmad Bhāgavatam"]|//a[text()="<<<"]/parent::*|//a[text()="<<<"]/parent::*/following::p',
                  document,
                  null,
                  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
                  null);
              for (var i = 0; i < element.snapshotLength; i++) {
                  var thisImg = element.snapshotItem(i);
                  thisImg.parentNode.removeChild(thisImg);
              }

              console.log(document.title);
          });

      });
      page.onLoadFinished = function () {
          //page.render('googleScreenShot' + '.png');
          fs.write('phantom.html', page.content, 'w');

      }

And i have to test on many htmls. So testing sake i used the following command

  find . -name "13.htm" -exec phantomjs 1.js {} \;

it says

    ReferenceError: Can't find variable: system

     1.js:3

because i have a directory with subfolders and many such htmls and i want to use phantomjs to modify them.

Upvotes: 2

Views: 2273

Answers (1)

dcodesmith
dcodesmith

Reputation: 9614

You have to load the system module using require as follows:

var system = require('system');

API Reference System Wiki

Page Loading Code

Upvotes: 6

Related Questions