首页 文章

幻像节点模块无法加载外部资源

提问于
浏览
3

我正在使用nodejs服务器,它将发布的html呈现为pdf,png或jpg . (https://github.com/svenhornberg/pagetox(server.js)如果你想试试)

它工作得非常好,渲染复杂的网站,但只是我想要加载一个简单的图像 . 例如,我将以下代码发送到我的服务器:

<!doctype html>
<html>
<head>
  <title>logo</title>
</head>
<body>
  <img alt="logo" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png">
</body>
</html>

守则应该没问题 . But the rendered response image does not contain the logo image. 如phantomjs文档(http://phantomjs.org/api/webpage/property/settings.html)中所述,localToRemoteUrlAccessEnabled设置为false,因此将其设置为true,如幻像节点(https://github.com/sgentle/phantomjs-node/)文档中所述:

page.set('settings.localToRemoteUrlAccessEnabled', true);
  page.set('settings.loadImages', true);

为了证明它设置为true,我调用了一个返回true的getter

page.get('settings.localToRemoteUrlAccessEnabled', function(data) { console.log(data);});

我在linux上使用节点v0.10.26与phantomjs-node(0.6.1),phantomjs(1.9.7)

Now the question, does anybody see a mistake ? Or can give me a hint what i am doing wrong. Or any other possibilities why phantomjs/phtanom-node isnt loading any external images

我正在使用render方法生成png,jpg或pdf文件 . 我将evaluate函数中的方法作为回调调用,因此应该完全加载该站点 . (完整代码位于https://github.com/svenhornberg/pagetox/blob/master/server.js

Edit1:我不在代理的后面,可能会阻止请求 .

2 回答

  • 0

    你想要设置的是什么

    page.set('settings.webSecurityEnabled', false);
    

    这启用了跨域请求 . 另一个选项 localToRemoteUrlAccessEnabled 不会影响您的情况,因为您不使用 file: 资源,而是覆盖:blank .

    其他问题可能与SSL / TLS相关 . 请参阅我的回答here以获得更多帮助 .

  • 0

    看起来我需要设置超时并等待所有外部资源都被加载 .

    page.set('content') dosen't work with dynamic content in phantomjs

    我让它工作,但超时不是我想要的 . 如果我发现任何更好的方式我会发布它 .

相关问题