casperjs在拆分文件后的中文乱码问题的解决

windows环境。

capserjs的中文乱码使用phantom.outputEncoding="GBK";即可解决。

但当我们脚本很大,需要拆分时(参考http://docs.casperjs.org/en/latest/writing_modules.html),拆分到另一文件(example.js)时,中文却无法echo出来。

后来发现, example.js是我们用记事本建立的,编码为ANSI,改为UTF-8编码即可正确显示中文。

延伸,若任意脚本为ansi编码,echo中文都会无法显示。示例如下。

 

main.js

phantom.outputEncoding="GBK";

var casper = require('casper').create();

var example= require('./example.js')

casper.echo('main你好');
example.say(); casper.run();

 

拆分的 example.js

var require = patchRequire(require);

exports.say = function () {
	casper.start('http://baidu.com',function then(){
		casper.echo('你好,百度')
  });
}

 

转载于:https://www.cnblogs.com/wigis/p/4132111.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值