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});