cheerio gb2312 转码问题

const iconv = require(‘iconv-lite’);
const request = require(‘request’);
headers: {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
            "Accept-Encoding": "gzip, deflate",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "no-cache",
            "Connection": "keep-alive",
            "Host": "www.cast.net.cn",
            "Pragma": "no-cache",
            "Referer": "http://www.cast.net.cn/",
            "Upgrade-Insecure-Requests": "1",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36",
            "x-forwarded-for": "127.0.0.1"
        },
        encoding:null

 

重点,在request库中一定要设置encoding:null
lethtml=iconv.decode(body,’gb2312′)
let$=cheerio.load(html,{decodeEntities: false});

发表评论

电子邮件地址不会被公开。 必填项已用*标注