phantomjs服务器linux32位系统安装使用记录

来源:互联网 发布:戴比尔斯钻石骗局 知乎 编辑:程序博客网 时间:2024/06/05 03:00

使用phantomjs遇到问题

chmod 777 phantomjs后

执行./phantomjs 出现./phantomjs-32: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

无脑安装~包:

yum install libxml2-devel

yum install contconfig fontconfig-devel

解决问题~指令可以执行./phantomjs-32 1.js

截图出现中文乱码

yum install bitmap-fonts bitmap-fonts-cjk  安装字体~
解决问题~
1.js内容如下

var page = new WebPage(),
    address, output, size;

if (phantom.args.length < 2 || phantom.args.length > 3) {
    console.log('Usage: rasterize.js URL filename');
    phantom.exit();
} else {
    address = phantom.args[0];
    output = phantom.args[1];
    page.viewportSize = { width: '100%', height: '100%' };
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
        } else {
            window.setTimeout(function () {
                page.render(output);
                phantom.exit();
            }, 200);
        }
    });
}

java中调指令:

List<String> commend = new java.util.ArrayList<String>();
         commend.add("chmod 777 "+phantomjs_path);
         commend.add(jspath);
         commend.add(url);
         commend.add(filePath+fileName);
ProcessBuilder builder = new ProcessBuilder();    
         builder.command(commend);    
         try {
            builder.start();
           


0 0
原创粉丝点击