相关疑难解决方法(0)

使用PhantomJS嵌入网页的所有图像会产生警告,但有效

我试图通过嵌入所有图像(以及我通过此点后的其他外部资源)将网页转换为单个文件.以下是我运行PhantomJs的方法:

./phantomjs --web-security=false ./embed_images.js http://localhost/index.html > output.txt
Run Code Online (Sandbox Code Playgroud)

这是embed_images.js:

var page = require('webpage').create(),
    system = require('system'),
    address;

if (system.args.length === 1) {
    console.log('Usage: embed_images.js <some URL>');
    phantom.exit(1);
}
else {
    page.onConsoleMessage = function(msg) {
        console.log(msg);
    };
    address = system.args[1];
    page.open(address, function(status) {
        page.evaluate(function() {
            function embedImg(org) {
                var img = new Image();
                img.src = org.src;
                img.onload = function() {
                    var canvas = document.createElement("canvas");
                    canvas.width = this.width;
                    canvas.height = this.height;

                    var ctx = canvas.getContext("2d");
                    ctx.drawImage(this, 0, 0);

                    var dataURL = …
Run Code Online (Sandbox Code Playgroud)

javascript embed phantomjs

14
推荐指数
1
解决办法
8321
查看次数

标签 统计

embed ×1

javascript ×1

phantomjs ×1