zoukankan      html  css  js  c++  java
  • phantomjs环境搭建已经运行

    1、下载phantomjs
    http://phantomjs.org/

    2、运行
    新建phantomjs.bat,记得改目录路径

    里面内容为:

    D:javaphantomjsphantomjs.exe D:javaphantomjscodeserver.js 8080

    3、新建server.js文件,放在code目录下,注意code目录也是新建的,以下是server.js内容

    if (s=== "success" ) {
                page.evaluate(function () {
                    $(".canvas_box").appendTo(".app_box").css("float","none").siblings().remove();
                    $(".app_box,body").css("margin",0);
                });
    
                var base64= page.renderBase64('png'),type="data:image/png;base64,"
                var img="<img src='"+type+base64+"'>"
                res.write(img);
                res.close();
            }var page = require('webpage').create();
    var server = require('webserver').create();
    var sys = require('system');
    
    if(sys.args.length !== 2){
        console.log('args is error,demo: phantomjs server.js 80');
        phantom.exit(1);
    }else{
        console.log("welcome! system is start on port:"+sys.args[1]+"
    test url is: http://localhost/http://www.baidu.com");
    }
     
    var port = sys.args[1];
     
    //输出到网页预览图片,地址:http://localhost/http://www.baidu.com
    /*
    service = server.listen(port,function(req, res){
        var url=decodeURIComponent(req.url).substr(1);
        res.statusCode = 200;
        res.headers = {
            'Cache': 'no-cache',
            'Content-Type': 'text/html;charset=utf-8'
        };
    
        page.open(url, function (s) {
            if (s=== "success" ) {
                page.evaluate(function () {
                    $(".canvas_box").appendTo(".app_box").css("float","none").siblings().remove();
                    $(".app_box,body").css("margin",0);
                });
    
                var base64= page.renderBase64('png'),type="data:image/png;base64,"
                var img="<img src='"+type+base64+"'>"
                res.write(img);
                res.close();
            }
        });
    });*/
    
    
    //输出base64字符串
    service = server.listen(port,function(req, res){
        var url=decodeURIComponent(req.url).substr(1);
        res.statusCode = 200;
        res.headers = {
            'Cache': 'no-cache',
            'Content-Type': 'text/html;charset=utf-8'
        };
    
        page.open(url,/*{ keepAlive: true },*/ function (s) {
           var base64= page.renderBase64('png');
            res.write(base64);
            res.close();
        });
    });
    
    
     

    4:訪问地址

    localhost:8080/http://baidu.com



  • 相关阅读:
    laravel5.2总结--blade模板
    laravel5.2总结--响应
    laravel5.2总结--请求
    git总结
    laravel5.2总结--路由
    Get与Post的一些总结
    python库安装
    iptables的recent模块
    iptables
    dmucs与distcc
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4005366.html
Copyright © 2011-2022 走看看