PhantomJS
来源:互联网 发布:樱井知香黑人 编辑:程序博客网 时间:2024/06/05 04:43
phantomjs 加ua以及设置中文编码的方式,如下面这两句代码所示,如果不设置中文编码,redhat环境下是乱码的
page.settings.userAgent='Mozilla/6.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/8.0 Mobile/10A5376e Safari/8536.25'; phantom.outputEncoding = "gb2312";
先安装字体
yum install bitmap-fonts bitmap-fonts-cjk
"use strict";var page = require('webpage').create(), system = require('system'), address, output, size; page.settings.userAgent='Mozilla/6.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/8.0 Mobile/10A5376e Safari/8536.25'; phantom.outputEncoding = "gb2312"; if (system.args.length < 3 || system.args.length > 5) { console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"'); console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px'); console.log(' "800px*600px" window, clipped to 800x600'); phantom.exit(1);} else { address = system.args[1]; output = system.args[2]; page.viewportSize = { width: 414, height: 736 }; if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") { size = system.args[3].split('*'); page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' } : { format: system.args[3], orientation: 'portrait', margin: '1cm' }; } else if (system.args.length > 3 && system.args[3].substr(-2) === "px") { size = system.args[3].split('*'); if (size.length === 2) { var pageWidth = parseInt(size[0], 10); var pageHeight = parseInt(size[1], 10); page.viewportSize = { width: pageWidth, height: pageHeight }; page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight }; } else { console.log("size:", system.args[3]); var pageWidth = parseInt(system.args[3], 10); var pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any console.log ("pageHeight:",pageHeight); page.viewportSize = { width: pageWidth, height: pageHeight }; } } if (system.args.length > 4) { page.zoomFactor = system.args[4]; } page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(1); } else { window.setTimeout(function () { page.render(output); phantom.exit(); }, 200); } });}
0 0
- phantomjs
- phantomjs
- phantomjs
- PhantomJS
- PhantomJS
- phantomjs
- phantomjs
- PhantomJS
- phantomjs
- 安装phantomjs
- python phantomjs
- 推荐 phantomjs
- phantomjs note
- phantomjs 简介
- phantomjs入门教程
- 安装phantomjs
- phantomjs使用说明
- phantomjs使用说明
- HDU 1058 Humble Numbers(打表+暴力)
- 浅谈HashMap
- 面试:数组:插入区间:057
- Linux网络编程-客户端和服务器端互相收发消息
- 提高PHP代码质量的36个技巧
- PhantomJS
- 如何学习java
- 图片,还可以这样玩儿
- angularjs结合localstorage完成一个简单的备忘录
- EditText点击事件——弹出单选框
- HDU2544 最短路 + 裸 + dijkstra + 邻接矩阵
- C++ limits头文件的用法(numeric_limits)
- js---匿名函数和闭包
- java基础之try-catch-finally