gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:33:43 25 4
gpt4 key购买 nike

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

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com