对于gb2312编码的网页,直接用request去获取会得到乱码的结果,解决方法很简单:
1. npm install iconv-lite
2. var iconv = require('iconv-lite');
3.
request.get({ url : url , encoding : null //让body 直接是buffer}, response);
4.
var response = function (err, response, body) { //返回的body 直接就是buffer 了... var buf = iconv.decode(body, 'gb2312'); ... ...}
done.