phantomjs命令行变量

San*_*idi 2 javascript linux phantomjs

我正在使用linux和phantomjs来测试一些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');

      }
Run Code Online (Sandbox Code Playgroud)

我必须测试很多htmls.所以测试我使用以下命令

  find . -name "13.htm" -exec phantomjs 1.js {} \;
Run Code Online (Sandbox Code Playgroud)

它说

    ReferenceError: Can't find variable: system

     1.js:3
Run Code Online (Sandbox Code Playgroud)

因为我有一个子文件夹和许多这样的htmls目录,我想使用phantomjs来修改它们.

dco*_*ith 6

您必须按如下方式加载system模块require:

var system = require('system');
Run Code Online (Sandbox Code Playgroud)

API参考系统Wiki

页面加载代码