【问题标题】:in phantomjs,how to create a filesystem variable within the page context在 phantomjs 中,如何在页面上下文中创建文件系统变量
【发布时间】:2017-02-06 15:11:02
【问题描述】:

在 phantomjs 脚本的页面上下文中为以下代码创建文件系统变量时,发现以下错误:

错误:尚未为上下文加载模块名称“fs”:_。使用要求([]) http://requirejs.org/docs/errors.html#notloaded

如何解决??

代码::

var page = require('webpage').create();
var fs=require('fs');

page.onConsoleMessage = function(msg, lineNum, sourceId) {
  console.log('CONSOLE: ' + msg);
};

page.onError = function(msg) {
  console.log('ERROR MESSAGE: ' + msg);
};

var filters;

page.open(url, function() {
  page.includeJs("http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js", function() {
    page.evaluate(function(filters) {
      var fs = require('fs');
      var stream = fs.open('outputs.txt');
      var v1 = document.getElementsByTagName("a");
      for(var i=0;i < v1.length; ++i)   
      { 
        //some operation
        console.log(temp);
      }
      stream.close();
    },fs);
    phantom.exit();
  });
}); 

【问题讨论】:

    标签: javascript file phantomjs


    【解决方案1】:

    从网页直接写入用户磁盘是不可能的,想象一下感染计算机会多么容易。

    而是将一个包含必要元素的数组返回给 PhantomJS 上下文并在那里写入磁盘。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 2013-08-08
      • 1970-01-01
      • 2015-09-23
      相关资源
      最近更新 更多