1、下载phantomjs
http://phantomjs.org/
2、执行
新建phantomjs.bat,记得改文件夹路径
4:访问地址
http://phantomjs.org/
2、执行
新建phantomjs.bat,记得改文件夹路径
里面内容为:
D:\java\phantomjs\phantomjs.exe D:\java\phantomjs\code\server.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]+"\ntest 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