我試圖使用phantomjs來屏幕捕獲我的頁面與node-phantom橋樑。這是我想要的:page.set('content')不適用於phantomjs中的動態內容
var phantom = require('node-phantom');
phantom.create(function (err, ph) {
return ph.createPage(function (err, page) {
return page.set('content', '<html><head></head><body><p>Hello</p></body></html>', function (err, status) {
return page.render('./content.png', function (err) {
ph.exit();
});
});
});
});
這工作正常,但如果我嘗試設置包含JavaScript的內容,這是行不通的。請幫助我,爲什麼它不起作用?
編輯:這不起作用:
var phantom = require('node-phantom');
phantom.create(function (err, ph) {
return ph.createPage(function (err, page) {
page.open("about:blank", function(err,status) {
page.evaluate(function() {
document.write('<html><head></head><body><script src="http://code.jquery.com/jquery-1.9.1.min.js"></script><script>$(function(){document.write("Hello from jQuery")})</script></body>');
});
setTimeout(function() {
return page.render('./content.png', function (err) {
ph.exit();
});
}, 5000);
});
});
遺憾的是它不工作。 page.evaluate不會被執行。 – Erik 2013-04-28 20:48:39