爬虫中文乱码可做如下处理

import request from 'superagent';
import cheerio from 'cheerio';//类似jquery写法
const  Iconv = require('iconv').Iconv;

const iconv = new Iconv('GBK', 'UTF-8');

request.get(url)
    .end(async(err, res) => {
        const result = iconv.convert(new Buffer(body, 'binary')).toString();
       const $ = cheerio.load(result);
     
//... })

 

posted on 2018-07-13 15:19  浅唱年华1920  阅读(181)  评论(0编辑  收藏  举报