page.set('content') 不适用于 phantomjs 中的动态内容

2023-12-10

我尝试使用 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 的内容,则不起作用。请帮助我,为什么它不起作用?

EDIT:这不起作用:

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);   
    });         
  });

JavaScript 代码需要一些时间来执行。尝试在设置页面内容和调用之间有一个延迟render.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

page.set('content') 不适用于 phantomjs 中的动态内容 的相关文章

随机推荐