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



  • 相关阅读:
    【MM 】采购合同成批维护
    【FICO 汇率】汇率
    【S4 MM】S4中继续使用MB系统事务代码(转)
    【MM 交货成本】Unplanned Delivery Cost
    Tracer Deployment UVALive
    The Best Path HDU
    Artwork Gym
    PTA 银行排队问题之单队列多窗口加VIP服务 队列+模拟
    Counting Cliques HDU
    Do not pour out HDU
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4005366.html
Copyright © 2011-2022 走看看