Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 从HTML代码创建页面的屏幕截图_Node.js_Phantomjs - Fatal编程技术网

Node.js 从HTML代码创建页面的屏幕截图

Node.js 从HTML代码创建页面的屏幕截图,node.js,phantomjs,Node.js,Phantomjs,我有一个网页的HTML内容,并希望以编程方式截图。我没有原始的URL,只有它的内容 有没有办法做到这一点 谢谢, Yannis在phantomjs中,您可以调用(“screenshot.png”)函数 由于您只有html代码,而没有url,要用html创建“页面”,您可以执行以下操作: var webPage = require('webpage'); var page = webPage.create(); page.open("file:///C://Full/Path/To/test.h

我有一个网页的HTML内容,并希望以编程方式截图。我没有原始的URL,只有它的内容

有没有办法做到这一点

谢谢, Yannis

在phantomjs中,您可以调用(“screenshot.png”)函数

由于您只有html代码,而没有url,要用html创建“页面”,您可以执行以下操作:

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

page.open("file:///C://Full/Path/To/test.html", function start(status) {
  page.render('screenshont.png');
  phantom.exit();
});

您可以将页面内容设置为字符串

var page = require('webpage').create();
page.content = '<html><body><p>Welcome to the Dark Side!</p></body></html>';
page.render('screenshont.png');
var page=require('webpage').create();
page.content='欢迎来到黑暗面

",; page.render('screenshont.png');
在web浏览器而不是记事本中打开内容…?嗯-我的意思是以编程方式…因此使用node.js/phantomjs标记