3

I have a script that works in PhantomJS but I'm trying to switch to SlimerJS. I keep getting an error when trying to open a local file:

var webPage = require('webpage');
var system = require('system');
var page = webPage.create();

page.viewportSize = { width: 2048, height: 1536 };
console.log('Processing',system.args[1]);
page.open(
  'simple.html',
  function start(status) {
    setTimeout(function(){
      page.render(system.args[2], {format: 'png'});
      phantom.exit();
    },1000);
  }
);

simple.html is a file located in the same directory as the script. The resulting PNG says "Address Not Found", "simple.html could not be found. Please check the name and try again."

I've also tried:

  • full OS path, eg /User/blah/blah/simple.html
  • file URI file:///Users/blah/blah/simple.html

These yield a similar result.

I'd rather not have the script publicly available for a variety of reasons. Is it possible to launch a local file with SlimerJS?

4

2 回答 2

0

文件 URI 确实有效。类似的东西file:///Users/name/project/file.html

于 2015-03-17T07:07:12.523 回答
0

我不认为这是可能的。阅读它指定一个网址的文档。

我通过运行 http 服务器解决了这个问题

python -m SimpleHTTPServer  

然后通过localhost访问它。

page.open('http://localhost:8000/simple.html',...)
于 2015-01-22T23:49:48.643 回答