node.js - meteor-webshot 无法截取屏幕截图并将其保存在服务器上

标签 node.js meteor phantomjs meteorite

在服务器上,我想截取外部链接的屏幕截图并将其保存到服务器的文件夹中。

我正在尝试使用 meteor 包 webshot:

https://github.com/TimHeckel/meteor-webshot

但是它不起作用。我使用 mrt add webshot 安装了该软件包。软件包安装成功。根据这个 stackoverflow:How to use webshot with meteor

我能够编辑 webshot 的 package.js 文件以导出 WEBSHOT 变量服务器端,如下所示:

Package.on_use(function (api) {
    api.add_files("lib/webshot.js", "server");
    api.export("WEBSHOT","server"); // This was the new line added to export WEBSHOT
});

这是我调用服务器端来拍摄网络快照的代码:

Meteor.methods 
  post: (postAttributes) ->
    console.log postAttributes.url // 'http://yahoo.com'
    _image = "myscreenshot.png";
    _res = WEBSHOT.snap(postAttributes.url, "public/exports~/" + _image,
      screenSize:
        width: 300
        height: 300
    )

我在公共(public)文件夹中有一个名为exports~的目录,当我运行代码时,没有图像保存到该目录中,并且我没有收到任何错误。我不知道发生了什么事!

由于我已经将 Meteor 设置为能够在服务器端安装 npm 软件包,因此我还尝试通过使用常规的旧 npm install webshot 进行安装来使用 npm webshot 软件包。

然后我尝试使用 webshot = Meteor.require('webshot') 但它从未起作用,因为我无法启动应用程序,因为它不断崩溃并出现如下错误:

node_modules/webshot/node_modules/phantomjs/node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template........

所以我无法使用 Meteor.require 来使用常规 npm 的 webshot。但我终于在使用 meteor 智能包时只要添加

api.export("WEBSHOT","server");

到 webshot 的 package.js 文件。但它仍然没有实际截图。请有人告诉我!

最佳答案

我从meteor-phantomjs git-hub页面追踪了你的问题。 我和你有同样的问题,使用meteor-phantomjs,现在我意识到我们需要将phantoms直接包含到项目中,因为meteor-phantomjs只包装一个环境路径,甚至它使用phantomjs-sun包。 (我不知道有什么区别)

所以我尝试直接使用 phantomjs,这是顺序。

1.安装phantomjs到服务器 2.将精确的phantomjs npm包版本添加到Meteor项目中的packages.json文件中 3.在Meteor源上使用Meteor.require('phantomjs')

但是还有另一个问题, 因为 Node phantomjs npm 包似乎只在 child_process 上执行 phantom-script.js 文件,仅此而已! 所以我认为我们必须按照我们想要的方式执行和控制数据。

可能会有一些误解,因为我是 Node 和 Meteor 的新手, 但我希望这会有所帮助。 谢谢。

关于node.js - meteor-webshot 无法截取屏幕截图并将其保存在服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24441963/

相关文章:

javascript - casperjs 测试一个内部站点

phantomjs - 使用 phantomjs 下载 csv(或其他非 html 数据)

node.js - Nodejs 使用什么 - Sequelize 在数据库中插入时删除空格

javascript - 停止/退出 Node.js 路由的正确方法是什么?

javascript - 无法弄清楚为什么我不断收到 [ERR_HTTP_HEADERS_SENT] 错误

javascript - D3-桑基错误 : Missing: (nodename)

javascript - 如何使用 MongoDB 在 MeteorJs 中存储用户操作?

node.js - 如何在 WebStorm 中为 webpack 添加运行配置?

meteor - 升级 meteor : Error when running mrt migrate-app

python - 使用phantomjs获取链接地址