比如将这个页面 div id="content" 的内容保存为图片
你也可以用nightmare
var Nightmare = require('nightmare');
var Screenshot = require('nightmare-screenshot');
var nightmare = new Nightmare();
nightmare
.viewport(1024, 700)
.goto(pageUrl)
.use(Screenshot.screenshotSelector(tempPath, '.question-answer-detail'));
var casper = require("casper").create({
verbose: true,
logLevel: "debug",
pageSettings: {
loadImages: true,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20100101 Firefox/17.0'
},
onError: function(self,m){
this.capture("error.png");
console.log("FATAL:" + m);
self.exit();
}
});
截图成功了,但是对应的div里面的图片是空的,这是什么原因
@okoala 运行提示没有模块Weak
npm install weak 没成功
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is most likely a problem with the weak package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls weak
npm ERR! There is likely additional logging output above.
npm ERR! node -v v0.10.34 npm ERR! npm -v 1.4.28 npm ERR! code ELIFECYCLE npm ERR! not ok code 0
@yakczh 应该是你的环境问题,卸载Visual C++ redistributable 然后重新安装 Windows SDK 7 SP1,windows下安装一些模块很麻烦,这种情况下建议使用virtualbox虚拟机,共享开发目录,在linux下运行node。